我在打开的文件中有以下代码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。
一个简单的解决方案是(将光标放在标签内的任何位置):
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.
我在一个更大的 html 块上尝试了带有环绕.vim 的 dst 解决方案。它可以工作,但它将所有子标签缩进到同一级别。它不应该改变缩进,把一切都搞砸了。
带有 yitvatp 的 Randys 解决方案也可以,但在粘贴标签之前和之后给我留下了一个空白行。
有什么完美的解决方案吗?