71

開いたファイルに次のコードがありますVim

<p>Hello stackoverflow!</p>

どうすれば削除<p>して</p>タグを付けることができますが、それらの間にコンテンツを保持できますか?つまり、何を押して終了する必要がありますか。

Hello stackoverflow!

押すd i tと逆になります。

Janusを使用しています。

4

5 に答える 5

100

Surround.vimプラグd s tインがインストールされている状態で、 を押して周囲タグを削除します。

同様のショートカット:

  • d s (- 周囲の括弧を削除()
  • d s "- 周囲の二重引用符を削除""
  • d s '- 周囲の一重引用符を削除''

等々...

于 2011-06-07T11:09:13.680 に答える
94

簡単な解決策は次のとおりです(タグ内の任意の場所にカーソルを置きます):

yitvatp

これが行うことは次のとおりです。

  • y-ヤンク
  • it- タグの内側
  • vat- タグ全体を選択
  • p- 以前にヤンクしたテキストをその上に貼り付けます
于 2011-06-07T11:05:12.877 に答える
6

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.
于 2011-06-07T15:13:57.070 に答える
4

これを選択したキーにマップします。

vat<Esc>da>`<da>

http://vim.wikia.com/wiki/Delete_a_pair_of_XML/HTML_tagsから取得

于 2011-06-07T10:43:31.060 に答える