Why is \r a newline for Vim?

后端 未结 5 2025
执笔经年
执笔经年 2020-11-27 09:30

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
         


        
5条回答
  •  隐瞒了意图╮
    2020-11-27 09:53

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

    • So you can't use \0 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.

    —☈

提交回复
热议问题