如何删除HTML标签,而不是Vim中的内容

ret*_*tro 62 html vim keyboard-shortcuts janus

我在打开的文件中有以下代码Vim:

<p>Hello stackoverflow!</p>
Run Code Online (Sandbox Code Playgroud)

如何删除<p></p>标记但保留它们之间的内容?也就是说,我应该按什么方式结束:

Hello stackoverflow!
Run Code Online (Sandbox Code Playgroud)

我知道紧迫d i t会做相反的事情.

我正在使用Janus.

Ran*_*ris 84

一个简单的解决方案是(将光标放在标签内的任何位置):

yitvatp
Run Code Online (Sandbox Code Playgroud)

这样做是:

  • y - 猛拉
  • it - 标签内部
  • vat - 选择整个标签
  • p - 将先前被拉动的文本粘贴在其上

  • 非常优雅的方式来做到这一点. (4认同)

Ben*_*oit 83

随着surround.vim安装的插件,按d s td elete 小号 urrounding 牛逼股份公司.

类似的快捷方式:

  • d s ( - 删除周围的括号 ()
  • d s " - 删除周围的双引号 ""
  • d s ' - 删除周围的单引号 ''

等等...


Rob*_*Rob 6

喜欢Randy的(+1)答案,我刚刚学习了标签块!这只是一个补充答案.

所以YIT意味着"猛拉内标签块"和增值税的意思是"去可视化模式并选择一个(整体)标签块".

这只适用于那些懒得阅读帮助文件的人:

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.
Run Code Online (Sandbox Code Playgroud)