Add a way to escape special keys in mappings
ndtodoroff opened this issue · comments
I would like a way of escaping special keys like <C-R>
in mapping. My particular use case is makeing a mapping that opens a hinted URI in another browser like Firefox. Consider the mapping
:nnoremap ;f :set x-hint-command=:sh! firefox '<C-R>;'<CR>;x
There are two issues with this
- The key sequence
<C-R>;
is executed as soon as;f
is pressed. - This means that
x-hint-command=:sh! firefox ''
. Notice that there's no way to get<CR>
at the end of this, so after a URI is hinted we're left with:sh! firefox ''
in the command line and have to press enter manually to execute the command.
In PR #752 I add the ability to escape with backslash, the result being that the mapping
:nnoremap ;f :set x-hint-command=:sh! firefox '\<C-R>;'\<CR><CR>;x
works as intended. The syntax \<C-R>
causes this string to be interpreted as the key sequence <
, C
, -
, R
, >
. The PR also adds a <Bslash>
special key so that <Bslash><C-R>
is backslash followed by CTRL-R.
Two questions that need to be answered:
- Syntax. Is this syntax ok? Would another syntax be more desirable? Another idea I had was to make
<<>
into a literal<
character, so that instead of\<C-R>
you would type<<>C-R>
. This would make it so that we don't need to add a<Bslash>
special key. - Is there already another way to accomplish the same things a new escape syntax would accomplish?