Putting Text in Insert and Replace Mode

One of my colleagues asked me how to paste over text in Vim. There are three steps to this:

  1. Enter the right mode (Replace): R
  2. Invoke the Insert/Replace mode’s “insert register contents” command: CTRL-R
  3. Press the key for a register: " for the last delete or yank, or * for the system clipboard

I’d wager that Replace mode is quite underused, and CTRL-R is even less common. If CTRL-R is new to you, the help page is available at :help i_CTRL-R — notice the preceding i_ for "Insert mode". This is a good command to learn because it means you can paste registers during editing, but you should generally prefer using Normal mode for yank/put because you'll get a more fine grained undo history.

Also, if you’re not used to “registers” and are a little scared off by the terminology, just remember that they’re only like extra copy and paste buffers and get filled when you perform certain operations. You can worry about what registers really are once you’ve got used to the basics.

If you’ve already learned yy for "yank line" and p for "put", then " will probably be the register you want. My colleague actually wanted * because he's using a Vim mode that's embedded in an IDE.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.