vimで文字列の単語を文字列にまとめる方法は?

vimで文字列の単語を文字列にまとめる方法は?

文字列と文字列ブロックが与えられると、例えば

ひも:

Use three words.

目詰まり:

This is the first string of another block of strings.
This is the second string of another block of strings.
This is the third string of another block of strings.

新しいブロックが次のように見えるように、文字列とブロックを1行ずつ連結/編成したいと思います。

This is the first string of another block of strings.
Use

This is the second string of another block of strings.
three

This is the third string of another block of strings.
words.

私がこれまでにしたことは

:'<,'>s/\s/\r\r\r

'<,'>s文字列にまたがる範囲はどこにありますかUse three words.?これにより、文字列の各単語が新しい行に表示されます。

Use


three


words.

その後、Ctrl+vブロックを選択してコピーして貼り付けると、次のような結果が表示されます。

This is the first string of another block of strings.
Use
     This is the second string of another block of strings.
three
     This is the third string of another block of strings.
words.

必要な形状に手動で変更し、ifvと使い方をたくさん使用しました。wx

vimの簡単なコピーと貼り付け手順を使用して、これをどのように効率的に実行できますか?

ベストアンサー1

貼り付けを置き換えることで、切り取りバッファから直接テキストを転送できます。選択置換に貼り付けると、そのdwVP行から削除された単語を除くすべての項目が削除されます。

から始まる

Use three words.
This is the first string of another block of strings.
This is the second string of another block of strings.
This is the third string of another block of strings.

そして

:normal ggdd    " three-word line in the cut buffer, cursor on first "This" line
:normal pdwVPo<ESC>j  " dwVP is cut a word and exchange-paste it back for the rest of the line
:normal pdwVPo<ESC>j  " do it again
:normal pdwVPo<ESC>j  " again

たった3回だけQQを実行せずにggddqqpdwVPo<ESC>jq@q@@短く進めます。

おすすめ記事