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

@@ -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