diff --git a/README.md b/README.md index 8e4a991..2abb7c3 100644 --- a/README.md +++ b/README.md @@ -291,21 +291,18 @@ since the same can be easily done using the negative N-th parameter: `-=` ### 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 `(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 a :set opfunc=easy_align_opg@ +nmap a (EasyAlignOperator) ``` -Now without going into visual mode, you can align the lines in the paragraph by -`aip=` or `aip:`. +Now without going into visual mode, you can align the lines in the paragraph +with `aip=`, `aip*|`, or `aip:`. -Or you can be more specific as follows, so you can do `=ip` or -`:ip`. +Or you can be more specific by defining custom operator functions as follows, so +you can do `=ip` or `:ip`. ```vim function! s:easy_align_1st_eq(type, ...) diff --git a/doc/easy_align.txt b/doc/easy_align.txt index 4c27f25..8de61fe 100644 --- a/doc/easy_align.txt +++ b/doc/easy_align.txt @@ -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 *(EasyAlignOperator)* +------------------------------------------------------------------------- + +With `(EasyAlignOperator)` map, EasyAlign command can be used as a Vim +operator that can be used with any Vim movement. + + nmap a (EasyAlignOperator) + +Now without going into visual mode, you can align the lines in the paragraph +with "aip=", "aip*|", or "aip:". + + Alignment options ------------------------------------------------------------------------- diff --git a/plugin/easy_align.vim b/plugin/easy_align.vim index 0334379..66156d3 100644 --- a/plugin/easy_align.vim +++ b/plugin/easy_align.vim @@ -28,3 +28,9 @@ let g:loaded_easy_align_plugin = 1 command! -nargs=* -range -bang EasyAlign ,call easy_align#align('' == '!', 0, ) command! -nargs=* -range -bang LiveEasyAlign ,call easy_align#align('' == '!', 1, ) + +function! s:easy_align_op(type, ...) + '[,']EasyAlign +endfunction +nnoremap (EasyAlignOperator) :set opfunc=easy_align_opg@ + diff --git a/test/interactive.vader b/test/interactive.vader index 8b884b8..4394e58 100644 --- a/test/interactive.vader +++ b/test/interactive.vader @@ -19,6 +19,7 @@ Execute (Clean up test environment): vnoremap r :EasyAlign! vnoremap :LiveEasyAlign vnoremap r :LiveEasyAlign! + nmap A (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): + \Aip*\ + +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 \\