diff --git a/README.md b/README.md index 8317fdd..d7645e5 100644 --- a/README.md +++ b/README.md @@ -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 . (EasyAlignRepeat) +``` + Usage ----- diff --git a/plugin/easy_align.vim b/plugin/easy_align.vim index 7a360d9..b5bd79d 100644 --- a/plugin/easy_align.vim +++ b/plugin/easy_align.vim @@ -51,7 +51,7 @@ function! s:repeat_visual() set virtualedit+=block endif execute cmd.":\=g:easy_align_last_command\\" - silent! call repeat#set("\(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("\(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('' == '!', a:live, vmode, '') end - silent! call repeat#set("\(EasyAlignRepeat)") + call s:set_repeat() finally let &selection = sel_save endtry @@ -119,6 +130,7 @@ vnoremap (LiveEasyAlign) :call live_easy_align_op(visua " vim-repeat support nnoremap (EasyAlignRepeat) :call easy_align_repeat() +vnoremap (EasyAlignRepeat) :call repeat_in_visual() " Backward-compatibility (deprecated) nnoremap (EasyAlignOperator) :set opfunc=easy_align_opg@ diff --git a/test/interactive.vader b/test/interactive.vader index 3c08a26..fa8fc47 100644 --- a/test/interactive.vader +++ b/test/interactive.vader @@ -26,6 +26,7 @@ Execute (Clean up test environment): vmap (EasyAlign) vmap (LiveEasyAlign) nmap A (EasyAlign) + vmap . (EasyAlignRepeat) ########################################################### @@ -1564,6 +1565,21 @@ Expect: aaaa = 4 _____ = 5 +Do (Repeatable in visual mode): + 2GvG\. + +Expect: + a = 1 + bb = 2 + ccc = 3 + dddd = 4 + + d = 1 + cc = 2 + bbb = 3 + aaaa = 4 + _____ = 5 + Given: :: a : 1 :: bb : 2