summaryrefslogtreecommitdiffstats
path: root/.vim/after
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2011-01-17 21:17:22 +0100
committerFlorian Pritz <bluewind@xssn.at>2011-01-17 21:17:22 +0100
commitd16669342859464f34d5d42a9cacc846d1439cc8 (patch)
treeb62ca624a4268f687d1cf76a673c22a3cf588a1c /.vim/after
parent70f0ef31d89e361cb7c37de9b1b73a829c41c9a4 (diff)
downloaddotfiles-d16669342859464f34d5d42a9cacc846d1439cc8.tar.gz
dotfiles-d16669342859464f34d5d42a9cacc846d1439cc8.tar.xz
add vim tabular plugin
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to '.vim/after')
-rw-r--r--.vim/after/plugin/TabularMaps.vim48
1 files changed, 48 insertions, 0 deletions
diff --git a/.vim/after/plugin/TabularMaps.vim b/.vim/after/plugin/TabularMaps.vim
new file mode 100644
index 0000000..20f7141
--- /dev/null
+++ b/.vim/after/plugin/TabularMaps.vim
@@ -0,0 +1,48 @@
+if !exists(':Tabularize')
+ finish " Tabular.vim wasn't loaded
+endif
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+AddTabularPattern! assignment /[|&+*/%<>=!~-]\@<!\([<>!=]=\|=\~\)\@![|&+*/%<>=!~-]*=/l1r1
+AddTabularPattern! two_spaces / /l0
+
+AddTabularPipeline! multiple_spaces / / map(a:lines, "substitute(v:val, ' *', ' ', 'g')") | tabular#TabularizeStrings(a:lines, ' ', 'l0')
+
+AddTabularPipeline! argument_list /(.*)/ map(a:lines, 'substitute(v:val, ''\s*\([(,)]\)\s*'', ''\1'', ''g'')')
+ \ | tabular#TabularizeStrings(a:lines, '[(,)]', 'l0')
+ \ | map(a:lines, 'substitute(v:val, ''\(\s*\),'', '',\1 '', "g")')
+ \ | map(a:lines, 'substitute(v:val, ''\s*)'', ")", "g")')
+
+function! SplitCDeclarations(lines)
+ let rv = []
+ for line in a:lines
+ " split the line into declaractions
+ let split = split(line, '\s*[,;]\s*')
+ " separate the type from the first declaration
+ let type = substitute(split[0], '\%(\%([&*]\s*\)*\)\=\k\+$', '', '')
+ " add the ; back on every declaration
+ call map(split, 'v:val . ";"')
+ " add the first element to the return as-is, and remove it from the list
+ let rv += [ remove(split, 0) ]
+ " transform the other elements by adding the type on at the beginning
+ call map(split, 'type . v:val')
+ " and add them all to the return
+ let rv += split
+ endfor
+ return rv
+endfunction
+
+AddTabularPipeline! split_declarations /,.*;/ SplitCDeclarations(a:lines)
+
+AddTabularPattern! ternary_operator /^.\{-}\zs?\|:/l1
+
+AddTabularPattern! cpp_io /<<\|>>/l1
+
+AddTabularPattern! pascal_assign /:=/l1
+
+AddTabularPattern! trailing_c_comments /\/\*\|\*\/\|\/\//l1
+
+let &cpo = s:save_cpo
+unlet s:save_cpo