Suppose I want to create a map in vim that will call an ex command as part of its work. And suppose that the ex command takes a register name as input.
Here is a toy example:
nmap <leader>p :put x
The problem there is that the ‘x’ register will always be used.
But when typing, I want to be able to write:
"a<leader>p
To use the ‘a’ register, or:
"b<leader>p
to use the ‘b’ register.
Is there a way that I can pass the ‘current normal-mode register’ along to the ‘ex’ command?
Ah, I figured it out.
The trick is to use
<expr>in the mapping.So, for my example, the answer is:
Check
:h map-expressionand:h v:registerfor more info.