在 Vim 中导航 HTML 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6270396/
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
Navigating HTML tags in Vim
提问by mazlix
I would like to be able to navigate through HTML tag by tag. Is there a way I can move from HTML tag to tag. (i.e. *<div>hi</div><div>bye</div>
---> <div>hi</div>*<div>bye</div>
I know about cit
and cat
, which is why I would imagine this is possible. Thanks!
我希望能够逐个标签地浏览 HTML 标签。有没有办法可以从 HTML 标签移动到标签。(即*<div>hi</div><div>bye</div>
---><div>hi</div>*<div>bye</div>
我知道cit
and cat
,这就是为什么我认为这是可能的。谢谢!
采纳答案by Michael Berkowski
The matchit.vim
macro gets you most of the way there, allowing you to move to a closing tag with %
as you would matching parens or braces. It's included in many Vim distributions including the standard download, but often not enabled by default.
在matchit.vim
宏观的存在方式最让你,让你移动到与关闭标签%
,你会匹配的括号或大括号。它包含在许多 Vim 发行版中,包括标准下载,但默认情况下通常不启用。
回答by kenorb
You can jump between tags using visual operators, in example:
您可以使用可视操作符在标签之间跳转,例如:
- Place the cursor on the tag.
- Enter visual mode by pressing v.
- Select the outer tag block by pressing a+tor i+tfor inner tag block.
- 将光标放在标签上。
- 按 进入可视模式v。
- 按a+t或i+选择外部标签块以选择t内部标签块。
Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press oor Oto jump to opposite tag.
您的光标应该向前跳到匹配的结束 html/xml 标记。要从结束标签向后跳,请按o或O跳到相反的标签。
Now you can either exit visual by pressing Esc, change it by cor copy by y.
现在,您可以通过按 退出视觉,通过Esc更改c或复制y。
To record that action into register, press qqto start recording, perform tag jump as above (including Esc), press qto finish. Then to invoke jump, press @q(to repeat, hit @@
).
将该动作记录到寄存器中,按qq开始记录,执行上述标签跳转(包括Esc),按q结束。然后调用跳转,按@q(to repeat, hit @@
)。
See more help at :help visual-operators
or :help v_it
:
在:help visual-operators
或 上查看更多帮助:help v_it
:
ata
<tag> </tag>
block (with tags)itinner
<tag> </tag>
block
at一个
<tag> </tag>
块(带标签)it内
<tag> </tag>
块
Alternatively use plugin such as matchit.vim(See: Using % in languages without curly braces).
或者使用诸如matchit.vim 之类的插件(请参阅:在没有花括号的语言中使用 %)。
See also:
也可以看看:
- How to jump between matching HTML/XML tags?at Vim SE
- Jump to matching XML tags in Vimat stackoverflow SE
- How can I find the close html tag quickly in vim?at stackoverflow SE
- How to navigate between begin and end html tag?at superuser SE
- VIM jump from one xml tag to the closing oneat Unix SE
- How can I select an html tag's content in Vim?at superuser SE
- 如何在匹配的 HTML/XML 标签之间跳转?在 Vim SE
- 在 stackoverflow SE跳转到 Vim中匹配的 XML 标签
- 如何在vim中快速找到关闭的html标签?在 stackoverflow SE
- 如何在开始和结束 html 标签之间导航?在超级用户 SE
- VIM 从一个 xml 标签跳转到Unix SE的结束标签
- 如何在 Vim 中选择 html 标签的内容?在超级用户 SE