就像编辑 C 源文件一样,我可以按 % 来获取当前光标 { 的结束}。 编辑 html 文件时如何执行此操作?有捷径吗? 明确地说,我想要:
<html>
</html>
当光标移动到<html>
时, 我想按一个键,让光标跳到</html>
.
最佳答案
您可以使用视觉运算符在标签之间跳转,例如:
- 将光标放在标签上。
- 按 v 进入可视模式。
- 通过按 a+t 或 i+t 选择外部标签 block 以选择内部标签 block 。
您的光标应向前跳转到匹配的结束 html/xml 标记。要从结束标签向后跳转,请按 o 或 O 跳转到相反的标签。
现在您可以按 Esc 退出可视化,按 c 更改它或按 y 复制。
要将该 Action 记录到寄存器中,按qq开始记录,如上执行标签跳转(包括Esc),按q结束。然后调用跳转,按@q。
在 :help visual-operators
查看更多帮助或 :help v_it
:
at a
<tag> </tag>
block (with tags)it inner
<tag> </tag>
block
或者使用插件,例如 matchit.vim (参见:Using % in languages without curly braces)。
另见:
- How to jump between matching HTML/XML tags?在 Vim SE
- Jump to matching XML tags in Vim在 stackoverflow SE
- Navigating HTML tags in Vim在 stackoverflow SE
- How to navigate between begin and end html tag?在 super 用户 SE
- VIM jump from one xml tag to the closing one在 Unix SE
- How can I select an html tag's content in Vim?在 super 用户 SE
关于html - 如何在 vim 中快速找到关闭的 html 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4116362/