<p>From question <em><a href="https://stackoverflow.com/questions/71323/how-to-replace-a-character-for-a-newline-in-vim">How to replace a character for a newline in Vim?</a></em>. You have to use \r when replacing text for a newline, like this</p>

<pre><code>:%s/%/\r/g
</code></pre>

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

<pre><code>:%s/\n/%/g 
</code></pre>

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

[{'answer_id': 71531, 'author': 'Aristotle Pagaltzis', 'author_id': 9410, 'author_profile': 'https://Stackoverflow.com/users/9410', 'pm_score': 6, 'selected': False, 'text': '<h3><a href="http://vimdoc.sf.net/htmldoc/pattern.html#NL-used-for-Nul" rel="noreferrer"><code>:help NL-used-for-Nul</code></a></h3>\n\n<blockquote>\n  <h3>Technical detail:</h3>\n  \n  <p><code>&lt;Nul&gt;</code> characters in the file are stored as <code>&lt;NL&gt;</code> in memory. In the display\n  they are shown as "<code>^@</code>".  The translation is done when reading and writing\n  files.  To match a <code>&lt;Nul&gt;</code> with a search pattern you can just enter <a href="http://www.vim.org/htmldoc/insert.html#i_CTRL-@" rel="noreferrer">CTRL-@</a> or\n  "<a href="http://www.vim.org/htmldoc/insert.html#i_CTRL-V" rel="noreferrer">CTRL-V</a> 000".  This is probably just what you expect.  Internally the\n  character is replaced with a <code>&lt;NL&gt;</code> in the search pattern.  What is unusual is\n  that typing <a href="http://www.vim.org/htmldoc/insert.html#i_CTRL-V" rel="noreferrer">CTRL-V</a> <a href="http://www.vim.org/htmldoc/insert.html#i_CTRL-J" rel="noreferrer">CTRL-J</a> also inserts a <code>&lt;NL&gt;</code>, thus also searches for a <code>&lt;Nul&gt;</code>\n  in the file.  {Vi cannot handle <code>&lt;Nul&gt;</code> characters in the file at all}</p>\n</blockquote>\n\n<hr>\n'}, {'answer_id': 73438, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 8, 'selected': True, 'text': '<p>From <a href="http://vimdoc.sourceforge.net/htmldoc/pattern.html#/%5Cr" rel="noreferrer">vim docs on patterns</a>:</p>\n\n<blockquote>\n  <p><code>\\r</code>  matches &lt;CR&gt;</p>\n  \n  <p><code>\\n</code>  matches an end-of-line - \n    When matching in a string instead of\n  buffer text a literal newline\n    character is matched.</p>\n</blockquote>\n'}, {'answer_id': 12388814, 'author': 'lmat - Reinstate Monica', 'author_id': 200985, 'author_profile': 'https://Stackoverflow.com/users/200985', 'pm_score': 8, 'selected': False, 'text': '<p>From <a href="http://vim.wikia.com/wiki/Search_and_replace" rel="noreferrer">http://vim.wikia.com/wiki/Search_and_replace</a> :</p>\n\n<blockquote>\n  <p><strong>When Searching</strong></p>\n  \n  <p>...</p>\n  \n  <p><code>\\n</code> is newline, <code>\\r</code> is <code>CR</code> (carriage return = <code>Ctrl-M</code> = <code>^M</code>)</p>\n  \n  <p><strong>When Replacing</strong></p>\n  \n  <p>...</p>\n  \n  <p><code>\\r</code> is newline, <code>\\n</code> is a null byte (<code>0x00</code>).</p>\n</blockquote>\n'}, {'answer_id': 12389839, 'author': 'rking', 'author_id': 1410840, 'author_profile': 'https://Stackoverflow.com/users/1410840', 'pm_score': 7, 'selected': False, 'text': '<p>Another aspect to this is that <code>\\0</code>, which is traditionally NULL, is taken in\n<code>s//\\0/</code> to mean "the whole matched pattern". (Which, by the way, is redundant with, and longer than, <code>&amp;</code>).</p>\n\n<ul>\n<li>So you can\'t use <code>\\0</code> to mean <code>NULL</code>, so you use <code>\\n</code></li>\n<li>So you can\'t use <code>\\n</code> to mean <code>\\n</code>, so you use <code>\\r</code>.</li>\n<li>So you can\'t use <code>\\r</code> to mean <code>\\r</code>, but I don\'t know who would want to add that char on purpose.</li>\n</ul>\n\n<p>—☈</p>\n'}, {'answer_id': 20491960, 'author': 'syockit', 'author_id': 219229, 'author_profile': 'https://Stackoverflow.com/users/219229', 'pm_score': 4, 'selected': False, 'text': '<p>First of all, open <a href="http://vimdoc.sourceforge.net/htmldoc/change.html#:s" rel="noreferrer"><code>:h :s</code></a> to see the section "4.2 Substitute" of documentation on "Change". Here\'s what the command accepts:</p>\n\n<pre><code>:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]\n</code></pre>\n\n<p>Notice the description about <code>pattern</code> and <code>string</code></p>\n\n<blockquote>\n  <p>For the <code>{pattern}</code> see <a href="http://vimdoc.sourceforge.net/htmldoc/pattern.html#pattern" rel="noreferrer"><code>|pattern|</code></a>. <br>\n  <code>{string}</code> can be a literal string, or something <br>\n  special; see <a href="http://vimdoc.sourceforge.net/htmldoc/change.html#sub-replace-special" rel="noreferrer"><code>|sub-replace-special|</code></a>.</p>\n</blockquote>\n\n<p>So now you know that the search pattern and replacement patterns follow different rules.\nIf you follow the link to <code>|pattern|</code>, it takes you to the section that explains the whole regexp patterns used in Vim.</p>\n\n<p>Meanwhile, <code>|sub-replace-special|</code> takes you to the subsection of "4.2 Substitute", which contains the patterns for substitution, among which is <code>\\r</code> for line break/split.</p>\n\n<p>(The shortcut to this part of manual is <a href="http://vimdoc.sourceforge.net/htmldoc/change.html#:s%25" rel="noreferrer"><code>:h :s%</code></a>)</p>\n'}]
['https://Stackoverflow.com/questions/71417', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5190/']