Skip to content

Instantly share code, notes, and snippets.

@gpakosz
Created February 26, 2013 08:20
Show Gist options
  • Save gpakosz/5036935 to your computer and use it in GitHub Desktop.
Save gpakosz/5036935 to your computer and use it in GitHub Desktop.
" -- tabular settings ----------------------------------------------------------
nnoremap <silent> <Leader>a= :Tabularize /=<CR>
vnoremap <silent> <Leader>a= :Tabularize /=<CR>
nnoremap <silent> <Leader>a: :Tabularize /:\zs<CR>
vnoremap <silent> <Leader>a: :Tabularize /:\zs<CR>
" auto align on pipes
inoremap <silent> <Bar> <Bar><Esc>:call <SID>pipe_align()<CR>a
function! s:pipe_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
" auto align on equals (often annoying, kept here for reference)
" inoremap <silent> = =<Esc>:call <SID>equal_align()<CR>a
" function! s:equal_align()
" let p = '^.*=\s.*$'
" if exists(':Tabularize') && getline('.') =~# '^.*=' && (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