Make repeatable in visual mode

This commit is contained in:
Junegunn Choi
2013-12-06 02:11:57 +09:00
parent 9271fc3f8f
commit 6d85e93476
3 changed files with 39 additions and 2 deletions

View File

@@ -83,6 +83,15 @@ try these commands:
Notice that the commands are repeatable with `.` key if you have installed
[repeat.vim](https://github.com/tpope/vim-repeat).
If you want to repeat the previous alignment for the selected range in visual
mode, install [visualrepeat](https://github.com/vim-scripts/visualrepeat)
(recommended) or add the following mapping to your .vimrc.
```vim
" Repeat alignment in visual mode with . key
vmap . <Plug>(EasyAlignRepeat)
```
Usage
-----

View File

@@ -51,7 +51,7 @@ function! s:repeat_visual()
set virtualedit+=block
endif
execute cmd.":\<C-r>=g:easy_align_last_command\<Enter>\<Enter>"
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
call s:set_repeat()
finally
if ve_save != &virtualedit
let &virtualedit = ve_save
@@ -59,6 +59,17 @@ function! s:repeat_visual()
endtry
endfunction
function! s:repeat_in_visual()
if exists('g:easy_align_last_command')
call s:remember_visual(visualmode())
call s:repeat_visual()
endif
endfunction
function! s:set_repeat()
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
endfunction
function! s:generic_easy_align_op(type, vmode, live)
let sel_save = &selection
let &selection = "inclusive"
@@ -85,7 +96,7 @@ function! s:generic_easy_align_op(type, vmode, live)
else
'<,'>call easy_align#align('<bang>' == '!', a:live, vmode, '')
end
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
call s:set_repeat()
finally
let &selection = sel_save
endtry
@@ -119,6 +130,7 @@ vnoremap <silent> <Plug>(LiveEasyAlign) :<C-U>call <SID>live_easy_align_op(visua
" vim-repeat support
nnoremap <silent> <Plug>(EasyAlignRepeat) :call <SID>easy_align_repeat()<Enter>
vnoremap <silent> <Plug>(EasyAlignRepeat) :<C-U>call <SID>repeat_in_visual()<Enter>
" Backward-compatibility (deprecated)
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@

View File

@@ -26,6 +26,7 @@ Execute (Clean up test environment):
vmap <Enter> <Plug>(EasyAlign)
vmap <leader><Enter> <Plug>(LiveEasyAlign)
nmap <leader>A <Plug>(EasyAlign)
vmap <leader>. <Plug>(EasyAlignRepeat)
###########################################################
@@ -1564,6 +1565,21 @@ Expect:
aaaa = 4
_____ = 5
Do (Repeatable in visual mode):
2GvG\<Space>.
Expect:
a = 1
bb = 2
ccc = 3
dddd = 4
d = 1
cc = 2
bbb = 3
aaaa = 4
_____ = 5
Given:
:: a : 1
:: bb : 2