12 changed files with 140 additions and 2 deletions
@ -0,0 +1,2 @@ |
|||
let b:div = "," |
|||
runtime! ftplugin/sep.vim |
@ -0,0 +1,66 @@ |
|||
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("<bang>") |
|||
|
|||
function! Align() |
|||
execute "normal! :Tabularize /" . b:div . "/l0\<CR>" |
|||
endfunction |
|||
command! Align :call Align() |
|||
|
|||
function! UnAlign() |
|||
execute "normal! |
|||
\:%s/ \\zs \\+\\ze//g\<CR> |
|||
\:%s/\\zs \\ze".b:div."//g\<CR> |
|||
\:noh\<CR>" |
|||
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\<C-v>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(<f-args>) |
|||
|
|||
execute "normal! :nnoremap <buffer> <tab> /" . b:div . "<CR>l:noh<CR>\<CR>" |
|||
execute "normal! :nnoremap <buffer> <s-tab> /" . b:div . "<CR>NNl:noh<CR>\<CR>" |
|||
" imap <buffer> <Esc> <Esc>mm:Align<CR>`m |
|||
nnoremap <buffer> <leader>s :Sort<CR> |
|||
nnoremap <buffer> <leader>S :Sort!<CR> |
|||
nnoremap <buffer> <leader>m1 :MoveColumn 1<CR> |
|||
nnoremap <buffer> <leader>m2 :MoveColumn 2<CR> |
|||
nnoremap <buffer> <leader>m3 :MoveColumn 3<CR> |
|||
nnoremap <buffer> <leader>m4 :MoveColumn 4<CR> |
|||
nnoremap <buffer> <leader>m5 :MoveColumn 5<CR> |
|||
nnoremap <buffer> <leader>m6 :MoveColumn 6<CR> |
|
@ -0,0 +1,2 @@ |
|||
let b:div = "\t" |
|||
runtime! ftplugin/sep.vim |
@ -0,0 +1,17 @@ |
|||
runtime syntax/sep.vim |
|||
syn match Tcolumn6 /.\{-}\(,\|$\)/ nextgroup=Tcolumn0 |
|||
syn match Tcolumn5 /.\{-}\(,\|$\)/ nextgroup=Tcolumn6 |
|||
syn match Tcolumn4 /.\{-}\(,\|$\)/ nextgroup=Tcolumn5 |
|||
syn match Tcolumn3 /.\{-}\(,\|$\)/ nextgroup=Tcolumn4 |
|||
syn match Tcolumn2 /.\{-}\(,\|$\)/ nextgroup=Tcolumn3 |
|||
syn match Tcolumn1 /.\{-}\(,\|$\)/ nextgroup=Tcolumn2 |
|||
syn match Tcolumn0 /.\{-}\(,\|$\)/ nextgroup=Tcolumn1 |
|||
syn match Tcolumn6title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn0title |
|||
syn match Tcolumn5title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn6title |
|||
syn match Tcolumn4title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn5title |
|||
syn match Tcolumn3title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn4title |
|||
syn match Tcolumn2title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn3title |
|||
syn match Tcolumn1title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn2title |
|||
syn match Tcolumn0title /\%1l.\{-}\(,\|$\)/ nextgroup=Tcolumn1title |
|||
syn match Tdiv /,/ containedin=ALL conceal cchar=| |
|||
setlocal conceallevel=2 |
@ -0,0 +1,24 @@ |
|||
syn match bluebg /\<blue\>\s*/ containedin=ALL |
|||
syn match magentabg /\<magenta\>\s*/ containedin=ALL |
|||
syn match yellowbg /\<yellow\>\s*/ containedin=ALL |
|||
syn match violetbg /\<violet\>\s*/ containedin=ALL |
|||
syn match greenbg /\<green\>\s*/ containedin=ALL |
|||
syn match cyanbg /\<cyan\>\s*/ containedin=ALL |
|||
syn match orangebg /\<orange\>\s*/ containedin=ALL |
|||
|
|||
hi def link Tdiv base01 |
|||
hi def link Tcolumn0 blue |
|||
hi def link Tcolumn0title blueu |
|||
hi def link Tcolumn1 magenta |
|||
hi def link Tcolumn1title magentau |
|||
hi def link Tcolumn2 yellow |
|||
hi def link Tcolumn2title yellowu |
|||
hi def link Tcolumn3 violet |
|||
hi def link Tcolumn3title violetu |
|||
hi def link Tcolumn4 green |
|||
hi def link Tcolumn4title greenu |
|||
hi def link Tcolumn5 cyan |
|||
hi def link Tcolumn5title cyanu |
|||
hi def link Tcolumn6 orange |
|||
hi def link Tcolumn6title orangeu |
|||
setl nowrap |
@ -0,0 +1,16 @@ |
|||
runtime syntax/sep.vim |
|||
syn match Tcolumn6 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn0 |
|||
syn match Tcolumn5 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn6 |
|||
syn match Tcolumn4 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn5 |
|||
syn match Tcolumn3 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn4 |
|||
syn match Tcolumn2 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn3 |
|||
syn match Tcolumn1 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn2 |
|||
syn match Tcolumn0 /.\{-}\(\t\|$\)/ nextgroup=Tcolumn1 |
|||
syn match Tcolumn6title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn0title |
|||
syn match Tcolumn5title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn6title |
|||
syn match Tcolumn4title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn5title |
|||
syn match Tcolumn3title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn4title |
|||
syn match Tcolumn2title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn3title |
|||
syn match Tcolumn1title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn2title |
|||
syn match Tcolumn0title /\%1l.\{-}\(\t\|$\)/ nextgroup=Tcolumn1title |
|||
syn match Tdiv /\t/ containedin=ALL |
@ -0,0 +1 @@ |
|||
au BufNewFile,BufRead *.csv set filetype=csv syntax=csv |
@ -0,0 +1 @@ |
|||
au BufNewFile,BufRead *.tsv set filetype=tsv syntax=tsv |
Loading…
Reference in new issue