Why is \r a newline for Vim?

From question How to replace a character for a newline in Vim?. 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?


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.


From http://vim.wikia.com/wiki/Search_and_replace :

When Searching

...

n is newline, r is CR (carriage return = Ctrl-M = ^M )

When Replacing

...

r is newline, n is a null byte ( 0x00 ).


Another aspect to this is that , which is traditionally NULL, is taken in s/// to mean "the whole matched pattern". (Which, by the way, is redundant with, and longer than, & ).

  • So you can't use to mean NULL , so you use n
  • So you can't use n to mean n , so you use r .
  • So you can't use r to mean r , but I don't know who would want to add that char on purpose.
  • —☈

    链接地址: http://www.djcxy.com/p/8674.html

    上一篇: Visual Studio:快捷键:重复行

    下一篇: 为什么\ ra为Vim换行?