Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. " The contents of this file are mostly from a Gist by Tim Pope
  2. " (https://gist.github.com/287147) with minor adjustments.
  3.  
  4. inoremap <buffer> <silent> <bar> <bar><esc>:call <sid>TabularizeCucumberTables()<cr>a
  5.  
  6. function! s:TabularizeCucumberTables()
  7.   let p = '^\s*|\s.*\s|\s*$'
  8.   if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  9.     let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  10.     let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  11.     Tabularize/|/l1
  12.     normal! 0
  13.     call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  14.   endif
  15. endfunction