The point of Virtual replace mode in Vim

vivim

The help says that virtual replace mode commands in Vim gr & GR replace characters in screen estate and not in file.

:help Virtual-Replace-mode

I am understanding this as something like changing the characters on the display but not in the buffer itself. Is that right? It seems incorrect.

I can use an explanation and probably a scenario or an example where this feature is relevant.

Best Answer

In Virtual-Replace-Mode the Buffer is harder fixed to its origin position.

1. Hello World
         ^ Cursor
2. I like cheese
3. And beer

When entering normal replace mode and hitting Internet<CR>And others the new buffer will be like this:

1. Hello Internet
2. And others
3. I like cheese
4. And beer

When doing the same in Virtual-Replace the result will be

1. Hello Internet
2. And othersese
3. And beer

Another example (tabstop=2;sts=0):

1. 012345678901234567890
2. Hello beautiful World
         ^ Cursor

Pressed keys: <Tab><Tab>

Replace-Mode result:

1. 012345678901234567890
2. Hello     autiful World

Virtual-Replace-Mode result:

1. 012345678901234567890
2. Hello     tiful World

Because in Replace mode the replacement is done char by char, where Tab is one char, no matter how many chars are displayed. In Virtual-Replace-Mode visible length of the Tab (:h 'ts', :h 'sts') is used to replace the chars.

Related Question