diff --git a/after/autoload/sep.vim b/after/autoload/sep.vim new file mode 100644 index 0000000..e69de29 diff --git a/after/ftplugin/csv.vim b/after/ftplugin/csv.vim new file mode 100644 index 0000000..cfd687d --- /dev/null +++ b/after/ftplugin/csv.vim @@ -0,0 +1,2 @@ +let b:div = "," +runtime! ftplugin/sep.vim diff --git a/after/ftplugin/sep.vim b/after/ftplugin/sep.vim new file mode 100644 index 0000000..0866948 --- /dev/null +++ b/after/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("") + +function! Align() + 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\" +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() + +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 diff --git a/after/ftplugin/test.csv b/after/ftplugin/test.csv new file mode 100644 index 0000000..af05fad --- /dev/null +++ b/after/ftplugin/test.csv @@ -0,0 +1,11 @@ +Letters,Numbers +a ,0 +a ,2 +a ,7 +b ,1 +d ,3 +e ,4 +f ,5 +g ,6 +z ,8 +z ,9 diff --git a/after/ftplugin/tsv.vim b/after/ftplugin/tsv.vim new file mode 100644 index 0000000..34f60cd --- /dev/null +++ b/after/ftplugin/tsv.vim @@ -0,0 +1,2 @@ +let b:div = "\t" +runtime! ftplugin/sep.vim diff --git a/after/syntax/csv.vim b/after/syntax/csv.vim new file mode 100644 index 0000000..34968a8 --- /dev/null +++ b/after/syntax/csv.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 diff --git a/after/syntax/sep.vim b/after/syntax/sep.vim new file mode 100644 index 0000000..cc5400c --- /dev/null +++ b/after/syntax/sep.vim @@ -0,0 +1,24 @@ +syn match bluebg /\\s*/ containedin=ALL +syn match magentabg /\\s*/ containedin=ALL +syn match yellowbg /\\s*/ containedin=ALL +syn match violetbg /\\s*/ containedin=ALL +syn match greenbg /\\s*/ containedin=ALL +syn match cyanbg /\\s*/ containedin=ALL +syn match orangebg /\\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 diff --git a/after/syntax/tsv.vim b/after/syntax/tsv.vim new file mode 100644 index 0000000..2b45e4c --- /dev/null +++ b/after/syntax/tsv.vim @@ -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 diff --git a/ftdetect/csv.vim b/ftdetect/csv.vim new file mode 100644 index 0000000..a510a3f --- /dev/null +++ b/ftdetect/csv.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.csv set filetype=csv syntax=csv diff --git a/ftdetect/tsv.vim b/ftdetect/tsv.vim new file mode 100644 index 0000000..c207852 --- /dev/null +++ b/ftdetect/tsv.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.tsv set filetype=tsv syntax=tsv diff --git a/plugins/paint.vim b/plugins/paint.vim deleted file mode 160000 index 1b6f95e..0000000 --- a/plugins/paint.vim +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1b6f95e61fdfe642f9cd0695dae017a58068ddc7 diff --git a/plugins/sep.vim b/plugins/sep.vim deleted file mode 160000 index 1b6f95e..0000000 --- a/plugins/sep.vim +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1b6f95e61fdfe642f9cd0695dae017a58068ddc7