在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