为什么 \r 是 Vim 的换行符? [英] Why is \r a newline for Vim?

查看:37
本文介绍了为什么 \r 是 Vim 的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自问题如何替换一个Vim 中的换行符?.替换换行符时必须使用 \r,就像这样

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?

推荐答案

来自 vim模式文档:

\r 匹配

\n 匹配行尾 -当匹配一个字符串而不是缓冲文本文字换行符字符匹配.

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

这篇关于为什么 \r 是 Vim 的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆