set foldmethod=manual function! GetColumn() let l:line = getline(line('.'))[0:col('.')] let l:count = count(l:line,b:div) + 1 return l:count endfunction function! SortByColumn(...) execute "normal! mm" let l:column = GetColumn() let l:column= l:column - 1 let reverse= get(a:, 1, 0) if reverse == "!" execute '2,$sort! /\(^\([^'.b:div.']*'.b:div.'\)\{'.l:column.'}\)\@<=[^'.b:div.']*/ r' " execute '2,$sort! /\([^'.b:div.']*'.b:div.'\)\{'.column.'}/' else execute '2,$sort /\(^\([^'.b:div.']*'.b:div.'\)\{'.l:column.'}\)\@<=[^'.b:div.']*/ r' " execute '2,$sort /\([^'.b:div.']*'.b:div.'\)\{'.column.'}/' endif execute "normal! `m" endfunction command! -nargs=0 -bang Sort :call SortByColumn("") function! Align() execute "normal! :Tabularize /" . b:div . "\" " execute "normal! :Tabularize /" . b:div . "/l0\" endfunction command! Align :call Align() function! UnAlign() " execute "normal! " \:%s/ \\zs \\+\\ze//g\ " \:%s/\\zs \\ze".b:div."//g\ " \:noh\" execute "normal! \:%s/ *" . b:div . " */".b:div."/g\ \:noh\" endfunction command! UnAlign :call UnAlign() function! MoveColumn(col) let l:target = a:col let l:current = GetColumn() if l:current < l:target let l:target = l:target - 1 endif if l:current != l:target execute "normal! ggF".b:div."l\Gf".b:div."x0" if a:col > 1 execute "normal! f".b:div if a:col > 2 execute "normal! " . repeat(";", a:col - 2) endif execute "normal! l" endif execute "normal! P" endif endfunction command! -nargs=1 MoveColumn :call MoveColumn() function! Filter(pattern) execute "normal! qaqqbqgg\"add" execute "g!/".a:pattern."/d B" execute "normal! gg\"aPG\"bpdd" execute ".,$fold" execute "g/^\s*$/de" execute "normal! gg" endfunction command! -nargs=1 Filter :call Filter() function! DeleteColumn() execute "normal! mm" execute "normal! /".b:div."\\|^\\$\" execute "normal! `mNgg\Gnhx" endfunction command! -nargs=0 Delete :call DeleteColumn() function CanApps() execute "normal! mm" execute "normal! /".b:div."\\|^\\$\" execute "normal! `mNggw\GIhttps://canapps.sanger.ac.uk/action/Cancer_Pipeline_Logs?id=\" endfunction command! CanApps :call CanApps() function UnFilter() execute "normal! zE" endfunction command! UnFilter :call UnFilter() function! SepFoldText() return repeat("-", winwidth(0)) endfunction setlocal foldtext=SepFoldText() execute "normal! :nnoremap /" . b:div . "l:noh\" execute "normal! :nnoremap /" . b:div . "NNl:noh\" imap mm:Align`m nnoremap s :Sort nnoremap S :Sort! nnoremap m1 :MoveColumn 1 nnoremap m2 :MoveColumn 2 nnoremap m3 :MoveColumn 3 nnoremap m4 :MoveColumn 4 nnoremap m5 :MoveColumn 5 nnoremap m6 :MoveColumn 6