When using <cmd>...<cr>
, there are some special keys such as <plug>
or <cmd>
that are not allowed to be contained inside the block. Trying to execute the command will result in:
E5521: <Cmd> mapping must end with <CR> before second <Cmd>
E5522: <Cmd> mapping must not include <Plug> key
However, sometimes these special keys may appear in the mapping, not to be executed, but inside strings. A practical example is vim-repeat. If you want to set it up by calling repeat#set
, there'll most likely be a <plug>
key in the string passed to the function:
<cmd>call repeat#set("\<Plug>MyWonderfulMap", v:count)<cr>
The "\<Plug>
" should not part of the execution, but simply part of the string. However, the above will still fail, since <Plug>
is still between <cmd>
and <cr>
. We are forced to use the :
alternative:
:call repeat#set("\<Plug>MyWonderfulMap", v:count)<cr>
This is sub-optimal however, since it does not work for insert and visual modes.
So knowing that, is there a way to pass the key <plug>
inside a function, without it being caught by the <cmd>...<cr>
block?
<Plug>
etc. in its body) and then call that function from the<Cmd>
.