I know how to create key mappings in normal mode using nmap and in insert mode using imap. However I do not know how to create mappings in replace mode. I would assume it's either rmap or Rmap, but both of these commands are invalid. Which command can I use to create mappings in replace mode in vim?


There has no rmap, replace mode map is created in imap with a mode test:

inoremap <expr> <a-k> mode() ==# 'R' ? 'replace' : 'insert'

:h mode() is transient, you must test it in :h map-expr.

Note it won't work for r.

| improve this answer | |
  • What is this command supposed to do? Sorry I do not know very much vimscript. – coder54321 May 22 at 1:58
  • @coder54321 It output replace or insert based on your current mode. The :h ... is valid ex command, you can execute it in vim to get help. – dedowsdi May 22 at 2:17

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.