chore(vim): Add Tabular plugin and custom alignment groups

This commit is contained in:
Stefan Imhoff
2021-12-11 13:44:31 +01:00
parent 4c0d2b54c6
commit 14d64e0dc2
3 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
" Custom Tabular Commands
AddTabularPattern! equals /^[^=]*\zs=/
AddTabularPattern! ruby_hash /^[^=>]*\zs=>/
AddTabularPattern! commas /,\s*\zs\s/l0
AddTabularPattern! colons /^[^:]*:\s*\zs\s/l0

View File

@@ -18,3 +18,17 @@ function! ToggleWrap()
setlocal display+=lastline
endif
endfunction
" Automatic Tabular.vim with the (|)
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

View File

@@ -18,5 +18,8 @@ Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Tpope
Plug 'tpope/vim-abolish'
" Misc
Plug 'godlygeek/tabular'
call plug#end()
doautocmd User PlugLoaded