Say I have a line with the only character, release the \n effect under different circumstances:
:s/s/a\nb a^@b :s/s/a\\nb a\nb :s/s/a\\\nb a\^@b :s/s/a\\\\nb a\\nb :echo "a\nb" a b :echo "a\\nb" a\nb :echo "a\\\nb" a\ b :echo "a\\\\nb" a\\nb
So why does \n behave differently? Then consider the condition using substitute()
:echo substitute(" ", " ", "a\nb", "") a b :echo substitute(" ", " ", "a\\nb", "") a b :echo substitute(" ", " ", "a\\\nb", "") a b :echo substitute(" ", " ", "a\\\\nb", "") a\nb
This time, \n is still interpreted as a "new line", but how to explain the backslash?
In the next part, let's say I still have a line with only the character ', instead of \n , \r will be studied:
:s/s/a\rb a b :s/s/a\\rb a\rb :s/s/a\\\rb a\ b :s/s/a\\\\rb a\\rb
\r effect is similar to \n in :echo "a\nb" , and the backslash rule is the same.
:echo "a\rb" b :echo "a\\rb" a\rb :echo "a\\\rb" b\ "This is the most strange case!!! :echo "a\\\\rb" a\\rb
What does \r in this case? And the third subtitle is even stranger.
:echo substitute(" ", " ", "a\rb", "") b :echo substitute(" ", " ", "a\\rb", "") b :echo substitute(" ", " ", "a\\\rb", "") b :echo substitute(" ", " ", "a\\\\rb", "") a\rb
However, I cannot understand how different numbers of backslashes behave.
My question is:
- Why do
\n or \r behave differently in :substitute , echo directly and substitute() ? - How to explain the different number of backslash effects when using
substitute() ? - What is the difference between
\n and \r in Vim?
Addition 1:
if I :let s = "a\\\nb" and then <Cr>=s to see it in the buffer, I see
a\ b
How to explain this?