chore(vim): move tabular function into plugin configuration file

This commit is contained in:
Stefan Imhoff
2021-12-12 16:58:42 +01:00
parent d14eb3398e
commit 91caaec00b
2 changed files with 15 additions and 14 deletions

View File

@@ -4,3 +4,18 @@ AddTabularPattern! equals /^[^=]*\zs=/
AddTabularPattern! ruby_hash /^[^=>]*\zs=>/
AddTabularPattern! commas /,\s*\zs\s/l0
AddTabularPattern! colons /^[^:]*:\s*\zs\s/l0
" Mappings
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
" Automatic Tabular.vim with the (|)
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

@@ -33,17 +33,3 @@ function! ToggleColorColumn()
set textwidth=80
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