在 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

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

Navigating HTML tags in Vim

htmlvim

提问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 citand 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>我知道citand cat,这就是为什么我认为这是可能的。谢谢!

采纳答案by Michael Berkowski

The matchit.vimmacro 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 发行版中,包括标准下载,但默认情况下通常不启用。

http://www.vim.org/scripts/script.php?script_id=39

http://www.vim.org/scripts/script.php?script_id=39

回答by kenorb

You can jump between tags using visual operators, in example:

您可以使用可视操作符在标签之间跳转,例如:

  1. Place the cursor on the tag.
  2. Enter visual mode by pressing v.
  3. Select the outer tag block by pressing a+tor i+tfor inner tag block.
  1. 将光标放在标签上。
  2. 按 进入可视模式v
  3. a+ti+选择外部标签块以选择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 标记。要从结束标签向后跳,请按oO跳到相反的标签。

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-operatorsor :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:

也可以看看: