Search code examples
vim

Difference between a 'string' vs. 'buffer text' in search commands when using line breaks (\n)


The following description is found in the line break (\n) section of the pattern and search commands in the official vim documentation. http://vimdoc.sourceforge.net/htmldoc/pattern.html#pattern-atoms

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

I don't understand

When matching in a string instead of buffer text a literal newline character is matched.

When can this be detected?

I have done the following experiment. I put the following in a file and typed /\n on the vim command line, but it did not match a literal newline character in all cases.

"\n"
'\n'
\n

Solution

  • By 'string' it doesn't mean text in the buffer that's surrounded by quotes, but rather the {string} argument that you would pass to the 'substitute' function. See :help substitute()