在vim中,我想用文字字符串替换换行符\n
。
例如,如果我打开一个包含以下文本的文件:
This is line one
This is line two
我想替换换行符并具有以下内容:
This is line one\nThis is line two
我怎样才能实现这个目标?
答案1
你必须转义你的替换的替换部分\
:1,$-1s/\n/\\n
分解
: start an ex command
1,$-1 over a range from the first line till the last but one
s/ substitute
\n all newlines
/ with
\\n literal string \n
答案2
看看这个:
:1,$-s/\n/\\n
这不会在文件末尾替换,因此:
This is line one\nThis is line two\nThis is line three