TabularMaps.vim (1776B)
1 if !exists(':Tabularize') 2 finish " Tabular.vim wasn't loaded 3 endif 4 5 let s:save_cpo = &cpo 6 set cpo&vim 7 8 AddTabularPattern! assignment /[|&+*/%<>=!~-]\@<!\([<>!=]=\|=\~\)\@![|&+*/%<>=!~-]*=/l1r1 9 AddTabularPattern! two_spaces / /l0 10 11 AddTabularPipeline! multiple_spaces / / map(a:lines, "substitute(v:val, ' *', ' ', 'g')") | tabular#TabularizeStrings(a:lines, ' ', 'l0') 12 13 AddTabularPipeline! argument_list /(.*)/ map(a:lines, 'substitute(v:val, ''\s*\([(,)]\)\s*'', ''\1'', ''g'')') 14 \ | tabular#TabularizeStrings(a:lines, '[(,)]', 'l0') 15 \ | map(a:lines, 'substitute(v:val, ''\(\s*\),'', '',\1 '', "g")') 16 \ | map(a:lines, 'substitute(v:val, ''\s*)'', ")", "g")') 17 18 function! SplitCDeclarations(lines) 19 let rv = [] 20 for line in a:lines 21 " split the line into declaractions 22 let split = split(line, '\s*[,;]\s*') 23 " separate the type from the first declaration 24 let type = substitute(split[0], '\%(\%([&*]\s*\)*\)\=\k\+$', '', '') 25 " add the ; back on every declaration 26 call map(split, 'v:val . ";"') 27 " add the first element to the return as-is, and remove it from the list 28 let rv += [ remove(split, 0) ] 29 " transform the other elements by adding the type on at the beginning 30 call map(split, 'type . v:val') 31 " and add them all to the return 32 let rv += split 33 endfor 34 return rv 35 endfunction 36 37 AddTabularPipeline! split_declarations /,.*;/ SplitCDeclarations(a:lines) 38 39 AddTabularPattern! ternary_operator /^.\{-}\zs?\|:/l1 40 41 AddTabularPattern! cpp_io /<<\|>>/l1 42 43 AddTabularPattern! pascal_assign /:=/l1 44 45 AddTabularPattern! trailing_c_comments /\/\*\|\*\/\|\/\//l1 46 47 let &cpo = s:save_cpo 48 unlet s:save_cpo