fanglingsu / vimb

Vimb - the vim like browser is a webkit based web browser that behaves like the vimperator plugin for the firefox and usage paradigms from the great editor vim. The goal of vimb is to build a completely keyboard-driven, efficient and pleasurable browsing-experience.
https://fanglingsu.github.io/vimb/
GNU General Public License v3.0
1.35k stars 100 forks source link

Add a way to escape special keys in mappings #753

Closed ndtodoroff closed 1 year ago

ndtodoroff commented 1 year ago

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

  1. The key sequence <C-R>; is executed as soon as ;f is pressed.
  2. 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:

  1. 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.
  2. Is there already another way to accomplish the same things a new escape syntax would accomplish?