Gregory Leeman 2 years ago
parent
commit
d4f968d63d
  1. 0
      after/autoload/sep.vim
  2. 2
      after/ftplugin/csv.vim
  3. 66
      after/ftplugin/sep.vim
  4. 11
      after/ftplugin/test.csv
  5. 2
      after/ftplugin/tsv.vim
  6. 17
      after/syntax/csv.vim
  7. 24
      after/syntax/sep.vim
  8. 16
      after/syntax/tsv.vim
  9. 1
      ftdetect/csv.vim
  10. 1
      ftdetect/tsv.vim
  11. 1
      plugins/paint.vim
  12. 1
      plugins/sep.vim

0
after/autoload/sep.vim

2
after/ftplugin/csv.vim

@ -0,0 +1,2 @@
let b:div = ","
runtime! ftplugin/sep.vim

66
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("<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>

11
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
1 Letters Numbers
2 a 0
3 a 2
4 a 7
5 b 1
6 d 3
7 e 4
8 f 5
9 g 6
10 z 8
11 z 9

2
after/ftplugin/tsv.vim

@ -0,0 +1,2 @@
let b:div = "\t"
runtime! ftplugin/sep.vim

17
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

24
after/syntax/sep.vim

@ -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

16
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

1
ftdetect/csv.vim

@ -0,0 +1 @@
au BufNewFile,BufRead *.csv set filetype=csv syntax=csv

1
ftdetect/tsv.vim

@ -0,0 +1 @@
au BufNewFile,BufRead *.tsv set filetype=tsv syntax=tsv

1
plugins/paint.vim

@ -1 +0,0 @@
Subproject commit 1b6f95e61fdfe642f9cd0695dae017a58068ddc7

1
plugins/sep.vim

@ -1 +0,0 @@
Subproject commit 1b6f95e61fdfe642f9cd0695dae017a58068ddc7
Loading…
Cancel
Save