Replace and Virtual Replace Modes

A great option to edit tables! Know how they work and the basic difference inbetween them.

Jonas B. Rossi
vim drops
4 min readJun 27, 2018

--

(alldrops.info is the TRUE and FOREVER FREE home for the previously used medium.com/vim-drops publication. At alldrops.info you’ll always find all posts without Medium.com restrictions.)

When you start learning Vim you're introduced to it's most used modes: INSERT, NORMAL and VISUAL. That's fair enough! You must get used to these modes because they'll be the core of your workflow.

But… Vim has more modes! Each one of them matches some specific needs, and that's the case of the REPLACE mode.

REPLACEmode is a very useful tool to edit tables, and you'll probably find some other use cases for it as well.

When you're in this mode, vim will overwrite what's under your cursor with what you're typing:

Let's understand how it works and it's behaviours.

REPLACE or VREPLACE mode?

Before start to use it, it's important to know a Vim improvement (not present on Vi), that is the Virtual Replace (VREPLACE ) mode, and understand why does it exist.

(VREPLACE mode isn't available when Vim is compiled without the +vreplace feature. On terminal type vim --version and check if +vreplace is there.)

— From Vim Docs:

REPLACE

In Replace mode, one character in the line is deleted for every character you type…

VREPLACE

… is similar to Replace mode, but instead of replacing actual characters in the file, you are replacing screen real estate

— What's the point?

The point is basically the <Tab> behaviour!

Let's say your <Tab> is set to 4 spaces, that means it's (4 spaces of screen real estate), and you're overwiting a spacing provided by the <Tab> character, with the letter a, let's see what happens:

REPLACE

When you type a to substitute the <Tab> character, it substitutes the 4 empty screen real estates to only 1 screen real estate, presenting the a character. The table looses the formatting.

VREPLACE

On Virtual Replace mode, you're substituting screen real estates, that means, if you have a table or a file with tab spacing/indentation, the content will not loose it's actual position and the table will keep the formatting.

How to use it:

You already know what to expect from each one of these two modes, so let's go to the commands.

Put the cursor where you want to start replacing and:

  • type R to enter REPLACE mode, or…
  • type gR to enter VREPLACE mode

Delete or Undo in REPLACE / VREPLACE modes

If you delete characters (with <BS>, <C-w>, or <C-u>), what happens is that you delete the changes:

Now you know almost everything about these modes! They are simple and useful, play with it and keep them in mind.

If you experience some unexpected behaviour, just type :help replace-mode and learn a little bit more… or ask me on the comments section, I'll be glad to help!

Do Not Miss It!

Get other useful tips like this one 👇 in your Twitter timeline:

Link to the original post: https://twitter.com/rossijonas/status/1033064293728706560?s=20

Useful links & references:

(👆 This is an affiliate link. If you got any value from this post and are also interested in buying the MVQ book/screencasts, please consider visiting the affiliate link and you’ll be gifting me a coffee ☕ or a beer 🍺.)

Footnotes:

  • alldrops.info is the TRUE and FOREVER FREE home for the previously used medium.com/vim-drops publication. At alldrops.info you’ll always find all posts without Medium.com restrictions.
  • If you have any doubts or tips about this article, I’d appreciate to know and to discuss it on the comments section.
  • Do you have any other vim tips? Would you like to publish that on this blog? Please send an email.
  • As English is not my native language, I apologize for the errors. Corrections are welcome.
  • Contact: vim [@] alldrops [.] info.

--

--

Jonas B. Rossi
vim drops

Project Manager | Software Engineer | Civil Engineer | MBA | #vim #cli addicted