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

发布于 2024-07-23 21:37:45 字数 194 浏览 4 评论 0原文

我知道

di<

会删除 HTML 标签本身。

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

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

谢谢!

I know

di<

will delete in an HTML tag itself.

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

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

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

才能让你更想念 2024-07-30 21:37:45

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

请参阅 :h it:h tag-blocks

dit will delete the text between matching XML tags. (it is for "inner tag block".)

See :h it and :h tag-blocks.

画尸师 2024-07-30 21:37:45
cit
ci"

vim 的两个最能提高生产力的命令。

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

cit
ci"

Two of the best productivity enabler commands of vim.

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

懷念過去 2024-07-30 21:37:45

dit - 删除内部标签,保持命令模式
cit - 更改内部标签,更改为编辑模式

di" - 删除内部 ""
di' - 删除 '' 内部

di( - 删除 () 内部
di) - 删除 () 内部

di[ - 删除 [] 内部
di] - 删除 [] 内部

di{ - 删除 {}
内部
di} - 删除 {}

di< 内部 - 删除里面的<>>
迪> -

如果您想在输入命令后进入编辑模式,请将第一个字母 d 替换为 c

dit - delete inner tag, remains in command mode
cit - change inner tag, changes to edit mode

di" - delete inside ""
di' - delete inside ''

di( - delete inside ()
di) - delete inside ()

di[ - delete inside []
di] - delete inside []

di{ -delete inside {}
di} - delete inside {}

di< - delete inside <>
di> - etc

swap first letter d for c, if you want to be in edit mode after typing the command

我要还你自由 2024-07-30 21:37:45

当光标位于要删除的第一个字符上时尝试 dt<。 在你的例子中是“H”。

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

夜访吸血鬼 2024-07-30 21:37:45

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

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

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

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

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

然后按:

20@a

对 20 个标签执行此操作

(cursor on first character to delete)
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.

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

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

then press:

20@a

to do this for 20 tags

栖迟 2024-07-30 21:37:45

这适用于光标所在的任何位置:

HTML

dit - 用于在命令模式下删除标签内容

cit - 用于删除标签内容,插入模式(首选方式)

STRING

dit - 用于删除仍处于命令模式的字符串内容

ci"/ci' - 用于删除字符串内容,插入模式(首选方式)

This applies to wherever your cursor is:

HTML

dit - for deleting tag content while still in command mode

cit - for deleting tag content, insert mode (Preferred Way)

STRING

dit - for deleting string content which still in command mode

ci"/ci' - for deleting string content, insert mode (Preferred Way)

美胚控场 2024-07-30 21:37:45

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文