Add <Plug>(EasyAlignOperator)

This commit is contained in:
Junegunn Choi
2013-11-30 13:04:32 +09:00
parent ddc1e00b81
commit 165bda1d95
4 changed files with 35 additions and 10 deletions

View File

@@ -291,21 +291,18 @@ since the same can be easily done using the negative N-th parameter: `<Enter>-=`
### EasyAlign as Vim operator ### EasyAlign as Vim operator
You can define an operator function which executes EasyAlign command, so that it With `<Plug>(EasyAlignOperator)` map, EasyAlign command can be used as a Vim
can be used with a Vim movement. operator that can be used with any Vim movement.
```vim ```vim
function! s:easy_align_op(type, ...) nmap <leader>a <Plug>(EasyAlignOperator)
'[,']EasyAlign
endfunction
nnoremap <silent> <Leader>a :set opfunc=<SID>easy_align_op<Enter>g@
``` ```
Now without going into visual mode, you can align the lines in the paragraph by Now without going into visual mode, you can align the lines in the paragraph
`<Leader>aip=` or `<Leader>aip:`. with `<Leader>aip=`, `<Leader>aip*|`, or `<Leader>aip:`.
Or you can be more specific as follows, so you can do `<Leader>=ip` or Or you can be more specific by defining custom operator functions as follows, so
`<Leader>:ip`. you can do `<Leader>=ip` or `<Leader>:ip`.
```vim ```vim
function! s:easy_align_1st_eq(type, ...) function! s:easy_align_1st_eq(type, ...)

View File

@@ -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. 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 Alignment options
------------------------------------------------------------------------- -------------------------------------------------------------------------

View File

@@ -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 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 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@

View File

@@ -19,6 +19,7 @@ Execute (Clean up test environment):
vnoremap <silent> r<Enter> :EasyAlign!<Enter> vnoremap <silent> r<Enter> :EasyAlign!<Enter>
vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter> vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter>
vnoremap <silent> <Leader>r<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 111 22 333 444 55555 6666 7 88888
1111 2 33 444 555 66 777 8 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): Do (right-align):
vip vip
\<Enter>\<Enter> \<Enter>\<Enter>