vim 可以像 Notepad++ 这样高亮匹配的 HTML 标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8168320/
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
Can vim highlight matching HTML tags like Notepad++?
提问by linqq
VIM has support for matching pairs of curly brackets, parentheses, and square brackets. This is great for editing C-style languages like PHP and Javascript. But what about matching HTML tags?
VIM 支持匹配成对的大括号、圆括号和方括号。这非常适合编辑 C 风格的语言,如 PHP 和 Javascript。但是如何匹配 HTML 标签呢?
Notepad++ has had this feature for as long as I've been using it. Being able to spot where blocks of HTML begin and end is very useful. What I'm looking for is something like this for vim (see the green div tags):
只要我一直在使用 Notepad++,它就具有此功能。能够发现 HTML 块的开始和结束位置非常有用。我正在为 vim 寻找类似这样的东西(请参阅绿色 div 标签):
(a bonus feature: highlighting unclosed HTML tags, like the red tag in this screenshot).
(一个额外的功能:突出显示未关闭的 HTML 标签,如此屏幕截图中的红色标签)。
matchithas been proposed as a next-best-thing, but it requires an extra keystroke to use its functionality. I'd like be able to see where the blocks of HTML begin and end without an extra keypress.
matchit已被提议为次佳之选,但它需要额外的击键才能使用其功能。我希望能够在没有额外按键的情况下看到 HTML 块的开始和结束位置。
I've trawled the internet to find something like this for vim. Apparently, I'm not the only one, according to 2 other StackOverflowquestionsand nabble.
我已经在互联网上搜索了 vim 的类似内容。显然,根据其他 2 个StackOverflow问题和nabble,我不是唯一一个。
I've almost resigned myself to vim not being able to visually match html tags. Is it possible for vim to do this?
我几乎让自己屈服于 vim 无法在视觉上匹配 html 标签。vim 有可能做到这一点吗?
Addendum: If it is not currently possible to do this with any existing plugins, does any vimscript wizard out there have any pointers on how to approach writing a suitable plugin?
附录:如果目前无法使用任何现有插件执行此操作,是否有任何 vimscript 向导有关如何编写合适的插件的指示?
回答by Greg Sexton
I had to work with some HTML today so thought I would tackle this. Added a ftplugin to vim.org that should solve your problem.
我今天不得不使用一些 HTML,所以我想我会解决这个问题。向 vim.org 添加了一个 ftplugin 应该可以解决您的问题。
You can get it here on vim.org.
You can get it here on github.
Hope it works for you. Let me know if you have any problems.
希望对你有效。如果您有任何问题,请告诉我。
回答by Valloric
Greg's MatchTag.vim plugin is awesome, but I wanted something more. I wanted the enclosing tags to alwaysbe highlighted, not just when the cursor is on one of the tags.
Greg 的 MatchTag.vim 插件很棒,但我想要更多。我希望始终突出显示封闭标签,而不仅仅是当光标位于其中一个标签上时。
So I wrote MatchTagAlwayswhich does everything that Greg's MatchTag does and also always highlights the enclosing tag, no matter where the cursor is in the code. It also works with unclosed tags and HTML templating languages like Jinja or Handlebars.
所以我编写了MatchTagAlways,它可以完成 Greg 的 MatchTag 所做的一切,并且始终突出显示封闭标签,无论光标在代码中的哪个位置。它还适用于未闭合的标签和 HTML 模板语言,如 Jinja 或 Handlebars。
Here's a GIF showing it in action:
这是一个 GIF 显示它在行动:
回答by Chris X
I came here looking for matching html style angle brackets in Vim. This seems to work:
我来这里是为了在 Vim 中寻找匹配的 html 样式尖括号。这似乎有效:
:set mps+=<:>
:help matchpairs