Vim - 改行文字を文字列 "\ n"に置き換える方法

Vim - 改行文字を文字列

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

おすすめ記事