~gpanders/dotfiles

ref: c8e63bac959db19c138dcc3198a56514f0b444ff dotfiles/.vim/after/plugin/easyalign.vim -rw-r--r-- 829 bytes
c8e63bacGreg Anders Manage dotfiles directly in home directory 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
" vim-easy-align configuration
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-02-28

if !get(g:, 'loaded_easy_align_plugin')
  finish
endif

let s:save_cpo = &cpo
set cpo&vim

nmap gl <Plug>(EasyAlign)
xmap gl <Plug>(EasyAlign)

" Source: https://gist.github.com/tpope/287147
inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  let l = line('.')
  if getline('.') =~# '^\s*|' && (getline(l-1) =~# p || getline(l+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    normal glip*|
    call cursor(l, 0)
    call search(repeat('[^|]*|', column) . '\s\{-\}' . repeat('.', position), 'ce', l)
  endif
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo