Search code examples
vimnewlinemode

vim - replace mode to replace new lines too


In VIM's replace mode, as you type, you don't add any new content, you just replace what is already there. Only problem is that you can add new content when you press enter. I'd like to know if there is a way so that pressing enter (or ^M) will be interpreted as down arrow when you're in replace mode?

If you must know, I'm working in a file that has segments that are given a fixed number of lines. I can't add new lines because it will offset subsequent segments.

Thanks in advance!


Solution

  • As far as I understand your requirements this can be achieved in the virtual replace mode. You can enter it via gR.

    Typing a <NL> still doesn't cause characters later in the file to appear to move. The rest of the current line will be replaced by the <NL> (that is, they are deleted), and replacing continues on the next line. A new line is NOT inserted unless you go past the end of the file.

    Please note that vim has to be compiled with +vreplace.