瀏覽代碼

Add plugin and vimscript (from tpope) to align cucumber tables

Andrew Swistak 11 年之前
父節點
當前提交
e1ce6e6c1a
共有 3 個文件被更改,包括 18 次插入0 次删除
  1. 3 0
      .gitmodules
  2. 1 0
      vim/bundle/tabular
  3. 14 0
      vimrc

+ 3 - 0
.gitmodules

@@ -98,3 +98,6 @@
 	path = vim/bundle/dbext.vim
 	url = https://github.com/vim-scripts/dbext.vim.git
   ignore = dirty
+[submodule "vim/bundle/tabular"]
+	path = vim/bundle/tabular
+	url = https://github.com/godlygeek/tabular.git

+ 1 - 0
vim/bundle/tabular

@@ -0,0 +1 @@
+Subproject commit 60f25648814f0695eeb6c1040d97adca93c4e0bb

+ 14 - 0
vimrc

@@ -315,3 +315,17 @@ fun! CloseWindow()
     endif
   endif
 endfunction
+
+" For auto-aligning cucumber tables
+inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a
+
+function! s:align()
+  let p = '^\s*|\s.*\s|\s*$'
+  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
+    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
+    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
+    Tabularize/|/l1
+    normal! 0
+    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
+  endif
+endfunction