mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-14 12:53:48 -05:00
Make repeatable in visual mode
This commit is contained in:
@@ -83,6 +83,15 @@ try these commands:
|
|||||||
Notice that the commands are repeatable with `.` key if you have installed
|
Notice that the commands are repeatable with `.` key if you have installed
|
||||||
[repeat.vim](https://github.com/tpope/vim-repeat).
|
[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
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function! s:repeat_visual()
|
|||||||
set virtualedit+=block
|
set virtualedit+=block
|
||||||
endif
|
endif
|
||||||
execute cmd.":\<C-r>=g:easy_align_last_command\<Enter>\<Enter>"
|
execute cmd.":\<C-r>=g:easy_align_last_command\<Enter>\<Enter>"
|
||||||
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
|
call s:set_repeat()
|
||||||
finally
|
finally
|
||||||
if ve_save != &virtualedit
|
if ve_save != &virtualedit
|
||||||
let &virtualedit = ve_save
|
let &virtualedit = ve_save
|
||||||
@@ -59,6 +59,17 @@ function! s:repeat_visual()
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
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)
|
function! s:generic_easy_align_op(type, vmode, live)
|
||||||
let sel_save = &selection
|
let sel_save = &selection
|
||||||
let &selection = "inclusive"
|
let &selection = "inclusive"
|
||||||
@@ -85,7 +96,7 @@ function! s:generic_easy_align_op(type, vmode, live)
|
|||||||
else
|
else
|
||||||
'<,'>call easy_align#align('<bang>' == '!', a:live, vmode, '')
|
'<,'>call easy_align#align('<bang>' == '!', a:live, vmode, '')
|
||||||
end
|
end
|
||||||
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
|
call s:set_repeat()
|
||||||
finally
|
finally
|
||||||
let &selection = sel_save
|
let &selection = sel_save
|
||||||
endtry
|
endtry
|
||||||
@@ -119,6 +130,7 @@ vnoremap <silent> <Plug>(LiveEasyAlign) :<C-U>call <SID>live_easy_align_op(visua
|
|||||||
|
|
||||||
" vim-repeat support
|
" vim-repeat support
|
||||||
nnoremap <silent> <Plug>(EasyAlignRepeat) :call <SID>easy_align_repeat()<Enter>
|
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)
|
" Backward-compatibility (deprecated)
|
||||||
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@
|
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Execute (Clean up test environment):
|
|||||||
vmap <Enter> <Plug>(EasyAlign)
|
vmap <Enter> <Plug>(EasyAlign)
|
||||||
vmap <leader><Enter> <Plug>(LiveEasyAlign)
|
vmap <leader><Enter> <Plug>(LiveEasyAlign)
|
||||||
nmap <leader>A <Plug>(EasyAlign)
|
nmap <leader>A <Plug>(EasyAlign)
|
||||||
|
vmap <leader>. <Plug>(EasyAlignRepeat)
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
@@ -1564,6 +1565,21 @@ Expect:
|
|||||||
aaaa = 4
|
aaaa = 4
|
||||||
_____ = 5
|
_____ = 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:
|
Given:
|
||||||
:: a : 1
|
:: a : 1
|
||||||
:: bb : 2
|
:: bb : 2
|
||||||
|
|||||||
Reference in New Issue
Block a user