tags:

views:

4549

answers:

2

From this question. You have to use \r when replacing text for a newline, like this

:%s/%/\r/g

But when replacing end of lines and newlines for a character, you can do it like:

:%s/\n/%/g

What section of the manual documents these behaviors, and what's the reasoning behind them?

+8  A: 

:help NL-used-for-Nul

Technical detail:

<Nul> characters in the file are stored as <NL> in memory. In the display they are shown as "^@". The translation is done when reading and writing files. To match a <Nul> with a search pattern you can just enter CTRL-@ or "CTRL-V 000". This is probably just what you expect. Internally the character is replaced with a <NL> in the search pattern. What is unusual is that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul> in the file. {Vi cannot handle <Nul> characters in the file at all}


Aristotle Pagaltzis
The link is broken.
molecules
Fixed it, thanks.
Aristotle Pagaltzis
+3  A: 

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.

pjz