<Plug>(EasyAlign) / <Plug>(LiveEasyAlign) for vim-repeat integration

This commit is contained in:
Junegunn Choi
2013-12-01 22:53:39 +09:00
parent 8d4d5b7941
commit da284f908e
5 changed files with 169 additions and 64 deletions

View File

@@ -26,11 +26,57 @@ if exists("g:loaded_easy_align_plugin")
endif
let g:loaded_easy_align_plugin = 1
command! -nargs=* -range -bang EasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 0, <q-args>)
command! -nargs=* -range -bang LiveEasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 1, <q-args>)
command! -nargs=* -range -bang EasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 0, '', <q-args>)
command! -nargs=* -range -bang LiveEasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 1, '', <q-args>)
function! s:generic_easy_align_op(type, vmode, live)
let sel_save = &selection
let &selection = "inclusive"
if a:vmode
let vmode = a:type
else
let tail = "\<C-c>"
if a:type == 'line'
silent execute "normal! '[V']".tail
elseif a:type == 'block'
silent execute "normal! `[\<C-V>`]".tail
else
silent execute "normal! `[v`]".tail
endif
let vmode = ''
endif
try
if get(g:, 'easy_align_need_repeat', 0)
execute "'<,'>". g:easy_align_last_command
else
'<,'>call easy_align#align('<bang>' == '!', a:live, vmode, '')
end
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
finally
unlet! g:easy_align_need_repeat
let &selection = sel_save
endtry
endfunction
function! s:easy_align_op(type, ...)
'[,']EasyAlign
call s:generic_easy_align_op(a:type, a:0, 0)
endfunction
function! s:live_easy_align_op(type, ...)
call s:generic_easy_align_op(a:type, a:0, 1)
endfunction
nnoremap <silent> <Plug>(EasyAlign) :set opfunc=<SID>easy_align_op<Enter>g@
vnoremap <silent> <Plug>(EasyAlign) :<C-U>call <SID>easy_align_op(visualmode(), 1)<Enter>
nnoremap <silent> <Plug>(LiveEasyAlign) :set opfunc=<SID>live_easy_align_op<Enter>g@
vnoremap <silent> <Plug>(LiveEasyAlign) :<C-U>call <SID>live_easy_align_op(visualmode(), 1)<Enter>
" vim-repeat support
nnoremap <silent> <Plug>(EasyAlignRepeat) :let g:easy_align_need_repeat = 1<Enter>.
vnoremap <silent> <Plug>(EasyAlignRepeat) :<C-U>let g:easy_align_need_repeat = 1<Enter>gv.
" Backward-compatibility (deprecated)
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@