mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-13 12:23:48 -05:00
Add <Plug>(EasyAlignOperator)
This commit is contained in:
17
README.md
17
README.md
@@ -291,21 +291,18 @@ since the same can be easily done using the negative N-th parameter: `<Enter>-=`
|
||||
|
||||
### EasyAlign as Vim operator
|
||||
|
||||
You can define an operator function which executes EasyAlign command, so that it
|
||||
can be used with a Vim movement.
|
||||
With `<Plug>(EasyAlignOperator)` map, EasyAlign command can be used as a Vim
|
||||
operator that can be used with any Vim movement.
|
||||
|
||||
```vim
|
||||
function! s:easy_align_op(type, ...)
|
||||
'[,']EasyAlign
|
||||
endfunction
|
||||
nnoremap <silent> <Leader>a :set opfunc=<SID>easy_align_op<Enter>g@
|
||||
nmap <leader>a <Plug>(EasyAlignOperator)
|
||||
```
|
||||
|
||||
Now without going into visual mode, you can align the lines in the paragraph by
|
||||
`<Leader>aip=` or `<Leader>aip:`.
|
||||
Now without going into visual mode, you can align the lines in the paragraph
|
||||
with `<Leader>aip=`, `<Leader>aip*|`, or `<Leader>aip:`.
|
||||
|
||||
Or you can be more specific as follows, so you can do `<Leader>=ip` or
|
||||
`<Leader>:ip`.
|
||||
Or you can be more specific by defining custom operator functions as follows, so
|
||||
you can do `<Leader>=ip` or `<Leader>:ip`.
|
||||
|
||||
```vim
|
||||
function! s:easy_align_1st_eq(type, ...)
|
||||
|
||||
@@ -228,6 +228,18 @@ In blockwise-visual mode (CTRL-V), EasyAlign command aligns only
|
||||
the selected text in the block, instead of the whole lines in the range.
|
||||
|
||||
|
||||
EasyAlign as Vim operator *<Plug>(EasyAlignOperator)*
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
With `<Plug>(EasyAlignOperator)` map, EasyAlign command can be used as a Vim
|
||||
operator that can be used with any Vim movement.
|
||||
|
||||
nmap <leader>a <Plug>(EasyAlignOperator)
|
||||
|
||||
Now without going into visual mode, you can align the lines in the paragraph
|
||||
with "<Leader>aip=", "<Leader>aip*|", or "<Leader>aip:".
|
||||
|
||||
|
||||
Alignment options
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -28,3 +28,9 @@ 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>)
|
||||
|
||||
function! s:easy_align_op(type, ...)
|
||||
'[,']EasyAlign
|
||||
endfunction
|
||||
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ Execute (Clean up test environment):
|
||||
vnoremap <silent> r<Enter> :EasyAlign!<Enter>
|
||||
vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter>
|
||||
vnoremap <silent> <Leader>r<Enter> :LiveEasyAlign!<Enter>
|
||||
nmap <leader>A <Plug>(EasyAlignOperator)
|
||||
|
||||
###########################################################
|
||||
|
||||
@@ -39,6 +40,15 @@ Expect:
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
Do (left-align using operator map):
|
||||
\<Space>Aip*\<Space>
|
||||
|
||||
Expect:
|
||||
1 22222 33 444 555 6666 7 888
|
||||
11 222 3333 4 55 6666 77 888
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
Do (right-align):
|
||||
vip
|
||||
\<Enter>\<Enter>
|
||||
|
||||
Reference in New Issue
Block a user