Skip to content

Instantly share code, notes, and snippets.

@derekbrokeit
Forked from tpope/cucumbertables.vim
Created February 11, 2012 08:03
Show Gist options
  • Save derekbrokeit/1797752 to your computer and use it in GitHub Desktop.
Save derekbrokeit/1797752 to your computer and use it in GitHub Desktop.
making sure that the behavior does not infiltrate other buffers (with different filetype) while in use; also changed to asciidoc
" added '<buffer>' to guard against this mapping from being used in other filetypes
inoremap <buffer><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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment