Carriage return vs newline in vim

newlinesvim

In vim, when I opened a file, I wanted to add two empty lines at the end of each current line. I used the following switch:

%s/$/\n\n/

Apparently, this does not work, but what does work is:

%s/$/\r\r/

I thought \r is a Windows feature? Would anyone be able to explain a bit more.

Best Answer

From vim docs on patterns:

\r matches <CR>

\n matches an end-of-line - When matching in a string instead of buffer text a literal newline character is matched.

Source: https://stackoverflow.com/questions/71417/why-is-r-a-newline-for-vim

Related Question