開いたファイルに次のコードがありますVim
。
<p>Hello stackoverflow!</p>
どうすれば削除<p>
して</p>
タグを付けることができますが、それらの間にコンテンツを保持できますか?つまり、何を押して終了する必要がありますか。
Hello stackoverflow!
押すd i tと逆になります。
Janusを使用しています。
開いたファイルに次のコードがありますVim
。
<p>Hello stackoverflow!</p>
どうすれば削除<p>
して</p>
タグを付けることができますが、それらの間にコンテンツを保持できますか?つまり、何を押して終了する必要がありますか。
Hello stackoverflow!
押すd i tと逆になります。
Janusを使用しています。
Surround.vimプラグd s tインがインストールされている状態で、 を押して周囲のタグを削除します。
同様のショートカット:
()
""
''
等々...
簡単な解決策は次のとおりです(タグ内の任意の場所にカーソルを置きます):
yitvatp
これが行うことは次のとおりです。
y
-ヤンクit
- タグの内側vat
- タグ全体を選択p
- 以前にヤンクしたテキストをその上に貼り付けますRandy の (+1) 回答が大好きで、タグ ブロックについて学びました。あくまで補足回答です。
つまり、yit は「内部タグ ブロックをヤンクする」ことを意味し、vat は「ビジュアル モードに移動して (全体の) タグ ブロックを選択する」ことを意味します。
これは、ヘルプ ファイルを読むのが面倒な人のためのものです。
Tag blocks *tag-blocks*
For the "it" and "at" text objects an attempt is done to select blocks between
matching tags for HTML and XML. But since these are not completely compatible
there are a few restrictions.
The normal method is to select a <tag> until the matching </tag>. For "at"
the tags are included, for "it" they are excluded. But when "it" is repeated
the tags will be included (otherwise nothing would change). Also, "it" used
on a tag block with no contents will select the leading tag.
"<aaa/>" items are skipped. Case is ignored, also for XML where case does
matter.
In HTML it is possible to have a tag like <br> or <meta ...> without a
matching end tag. These are ignored.
The text objects are tolerant about mistakes. Stray end tags are ignored.