複数行を引用符で囲む Vim

複数行を引用符で囲む Vim

次の形式のブロックがあります。

    String that is not supposed to be enclosed in quotes
    String that is supposed to be enclosed in quotes

    String that is not supposed to be enclosed in quotes
    String that is supposed to be enclosed in quotes

    String that is not supposed to be enclosed in quotes
    String that is supposed to be enclosed in quotes

    String that is not supposed to be enclosed in quotes
    String that is supposed to be enclosed in quotes

引用符で囲む必要があることを示す行を引用符で囲む必要があります。

    String that is not supposed to be enclosed in quotes
    "String that is supposed to be enclosed in quotes"

    String that is not supposed to be enclosed in quotes
    "String that is supposed to be enclosed in quotes"

    String that is not supposed to be enclosed in quotes
    "String that is supposed to be enclosed in quotes"

    String that is not supposed to be enclosed in quotes
    "String that is supposed to be enclosed in quotes"

Vimでこれを行う半自動方法はありますか?考えられる解決策にはgコマンドを含めることができると思います。

ベストアンサー1

正規表現を使用してください。

:%s/.*is supposed.*/"&"/

「半自動」が各置換の前にメッセージを表示したい場合は、/c交換パターンに修飾子を追加するだけです。

:%s/.*is supposed.*/"&"/c

説明する

  • :%sこの代替項目を現在のバッファのすべての行に適用することを意味します。
  • 私たちが一致するパターンは、単語を含むすべての行ですis supposed(他の行に「is Should」という単語が含まれ、「to be return in quote」が続く場合は、いつでもパターンを次のように変更できます)。.*is supposed to be enclosed in quotes.*
  • 一致するパターンを置き換えるために使用する文字列は、一致するパターンを表す"&"位置です。&

おすすめ記事