Html 在vim中删除HTML标签之间的文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/946188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:50:26  来源:igfitidea点击:

Delete text in between HTML tags in vim?

htmlvimeditor

提问by CMB

I know

我知道

di<

will delete in an HTML tag itself.

将删除 HTML 标签本身。

Is there an easy way to delete text in between two tags?

有没有一种简单的方法可以删除两个标签之间的文本?

<span>How can I delete this text?</span>

Thanks!

谢谢!

回答by Brian Carper

ditwill delete the text between matching XML tags. (itis for "inner tag block".)

dit将删除匹配的 XML 标记之间的文本。(it用于“内部标签块”。)

See :h itand :h tag-blocks.

:h it:h tag-blocks

回答by chipairon

cit
ci"

Two of the best productivity enabler commands of vim.

vim 的两个最佳生产力启动器命令。

I save a lot of time and effort with just those two.

我只用这两个就节省了很多时间和精力。

回答by JD Frias

try dt<while the cursor is on the first character to delete. In your example the 'H'.

尝试dt<当光标位于要删除的第一个字符上时。在您的示例中,'H'。

回答by brad

(cursor on first character to delete) v/<[enter]d

光标位于要删除的第一个字符上v/<[enter]d

This solution starts on the first character, then enters visual mode ("v"). It then searches for the next start bracket ("/<"), and then press enter to exit the search.

此解决方案从第一个字符开始,然后进入可视模式(“v”)。然后搜索下一个开始括号(“/<”),然后按回车键退出搜索。

At this point, your visual selection will cover the text to delete. press d ("d") to delete it.

此时,您的视觉选择将覆盖要删除的文本。按 d ("d") 删除它。

If I had to do this for a bunch of tags, I'd record the command and combine it with some other searches to make it repeatable. The key sequence might look like this:

如果我必须对一堆标签执行此操作,我会记录该命令并将其与其他一些搜索结合起来以使其可重复。键序列可能如下所示:

[cursor on start of file] qa/>[enter]lv/<[enter]dnq

[光标在文件开头] qa/>[enter]lv/<[enter]dnq

then press:

然后按:

20@a

20@a

to do this for 20 tags

为 20 个标签执行此操作

回答by Nick Sarafa

If you're aiming to do the inverse of deleting text between flags, I suggest installing Vim-Surroundand running dstwhich deletes the surround tag

如果您的目标是删除标志之间的文本,我建议安装Vim-Surround并运行dst它删除环绕标记