1

I have i-mapped <C-a>, <C-s> etc. to commonly used keys that I use often but find annoying to type normally, for example * and _. It works as expected in insert mode, but when executing a single-character replacement with r, I get some kind of escape sequence instead.

I've tried nnoremap r<C-(key)> character and nmap r<C-(key)> character, but seemingly-random things happen when i execute r<C-(key)>. Mapping to different characters (symbols) gives very different results. Prefixing the character with \ just makes nothing happen.

What is a way I can remap <C-(key)> while replacing a character?

1 Answer 1

1

This has to be done through the feature known as "language mapping". This feature allows entry of non-English/ASCII characters using a standard keyboard but more generally allows one to control the mapping of characters entered into a buffer which is what r emits.

You need to do two things:

  1. Use lmap for the mapping rather than imap. E.g. :lnoremap <c-a> *
  2. Enable language mapping. This can be done with :set iminsert=1 or by typing Ctrl^ (control-caret) while in insert mode.

Besides :h :lmap see :h 45.5, :h i_Ctrl-^ and :h 'iminsert'

Note that lmap also applies to characters entered while in Insert mode so lmap should be all you need for your general use case of replacing "annoying" characters with easier-to-type variants.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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