3

I'm trying to create a mapping to create a mapping such that pressing <C-return> presents me with :nnoremap <return> : to which I can then add a custom command. The following does not work because <return> is replaced by the return key.

:nnoremap <c-return> :nnoremap <return> :

I thought I could escape <return> as \<return>, but this does not seem to be working. How do I escape (or otherwise prevent nnoremap from expanding) <return> in the above statement?

4

Escape < as <lt>:

nnoremap <c-return> :nnoremap <lt>return> :

For more help see:

:h key-codes
  • Ah! I knew there was better way. – Tumbler41 Mar 21 '17 at 15:31
1

Interesting I thought we could do this with an exe command, but that fails too. I found a way to do it but it's pretty hacky:

:nnoremap <c-return> :nnoremap <return > :<c-left><c-left><BS><c-right><c-right>
  • <c-left>: executes Ctrl+
  • <c-right>: executes Ctrl+
  • <BS>: executes Backspace

We're basically breaking up the <return> so that it's not recognized and then we go back and delete the space. This works, but I'm curious if there is a better way of doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.