Why does Vim on windows use \n for searching?

Viewed 1177

So I was changing code from

foo()
{

to

foo() {

and I noticed that the searching pattern required me to search for \n, but when I tried to replace it with \n I got the ^@ character, and I had to instead replace with \r.

It seems strange to me that I search with \n and replace with \r, any idea why this might be?

For reference my solution was :%s/\n\s*{/ {\r/g

3 Answers

I gave up understanding clearly or remembering all about <NL>, <CR> etc., which is too complex and not used frequently. When I use them, just try.


In case this isn't all already bad enough:

:h sub-replace-special

        The special meaning is also used
        inside the third argument {sub} of the |substitute()| function
        with the following exceptions:
              . <CR> and \r inserts a carriage-return (CTRL-M).  
              . \<CR> does not have a special meaning. It's just one of \x.
              
              . A ~ inserts a tilde literally.
              . magic is always set without regard to 'magic'.

Related