When I'm going through text and, for instance, adding backticks around certain words or quotes or whatever, it is irritating that I have to press Esc or Ctrl-[ after each insert. The inserts (and appends) are different, so . doesn't help much.

Is there anything similar to r that returns to normal mode after a single character—but uses insert mode instead of replace mode?

  • 3
    You should perhaps consider using (or extending) the vim-surround plugin, in order to work on the text in a more meaningful way.
    – VanLaser
    Oct 19 '15 at 8:53

If there isn't (I haven't looked), you can use this mapping in your .vimrc:

nnoremap <C-I> i <ESC>r

It inserts, places a space, ESCapes, and starts a single letter replace. This gets mapped to CtrlI.

It's a hack, and will leave a hanging space if you hit escape before you type a letter - but it's better than nothing!

  • 1
    Not bad...I'll probably use that if no one comes up with anything better. :)
    – Wildcard
    Oct 19 '15 at 5:55
  • 3
    @Wildcard I didn't realize how much I actually run into this use case without realizing it. Good question :) I've added it to my own vimrc as well. Oct 19 '15 at 5:57
  • 3
    I spent most of the day fixing a bunch of markdown. Italics, inline code, header indentations, hyperlinks...all of them one character inserts. :) Actually your solution is perfect; I'm going to start using it now.
    – Wildcard
    Oct 19 '15 at 6:02
  • 2
    Disadvantage: It's not repeatable with the . command. :(
    – Wildcard
    Jan 29 '16 at 22:08
  • 1
    @Wildcard unfortunately, after doing a bit of research, there isn't a way to create a manual repeat branch for . unless you're using repeat.vim. Jan 30 '16 at 9:13

To insert a char at the end of a word (instead of at the cursor position), use

nnoremap <C-a> a <ESC>r

This maps to Ctrl + a, you can map it to anything else of course.

I have the two in my .vimrc just so I don't hustle much :)

" Insert char at cursor position
nnoremap <C-i> i <ESC>r
" Append char after cursor position
nnoremap <C-a> a <ESC>r

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.