Created
May 29, 2012 21:20
-
-
Save abatkin/2830780 to your computer and use it in GitHub Desktop.
.vim/after/plugin/tabular.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! FormatTableLine(line) | |
let curr_line = a:line | |
" Get rid of all leading or trailing spaces | |
let curr_line = substitute(curr_line, '^[ ]\{1,\}\|[ ]\{1,\}$', '', 'g') | |
" Replace all tabs with " | " | |
let curr_line = substitute(curr_line, '\t', ' | ', 'g') | |
" Possibly insert a leading | (if there isn't already one) | |
let curr_line = substitute(curr_line, '^\(|\)\@!', '| ', '') | |
" Possibly insert a trailing | (if there isn't already one) | |
let curr_line = substitute(curr_line, '\(|\)\@<!$', ' |', '') | |
return curr_line | |
endfunction | |
function! FormatPrettyTable() range | |
for linenum in range(a:firstline, a:lastline) | |
let curr_line = getline(linenum) | |
let curr_line = FormatTableLine(curr_line) | |
call setline(linenum, curr_line) | |
endfor | |
call Tabularize("/\|/") | |
endfunction | |
AddTabularPipeline! pretty_table /\t\|\(-\)\@<!|\(-\)\@!/ map(a:lines, "FormatTableLine(v:val)") | tabular#TabularizeStrings(a:lines, '|') | |
nmap <silent> <leader>pt :Tabularize pretty_table<cr> | |
nmap <silent> <leader>pp "+P:Tabularize pretty_table<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment