问题描述
限时送ChatGPT账号..我下载了 Matchit 插件并在我的 HTML 文件中使用了它.一切都按预期进行,直到我在我的清单上使用它.
<li id="link-1"><a href="http://www.reddit/">reddit</a></li><li id="link-2"><a href="http://www.vim/">vim</a></li><li id="link-3"><a href="http://www.w3schools/">w3schools</a></li></ol>
如果光标在第一个 o
上,当我按 Tab 键时,光标会跳转到第一个列表项而不是结束的 ol
.当我在第一个列表项的 l
上时,光标会跳转到下一个列表项标记的 l
.但是如果我将光标移到链接标签的第一个 a 并点击 Tab,那么 Matchit 工作得很好并跳转到结束标签.Matchit 适用于除列表项之外的所有标签?如何解决此行为?
首先,matchit 是随 Vim 分发的,没有被激活.您无需下载,只需按照 :help matchit-install
中的说明进行操作即可.
Matchit 使用名为 b:match_words
的缓冲区变量来定义匹配标签对:打开 HTML 文件并输入 echo b:match_words
.此处的值是:
<:>,<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>
如果我正确理解 :help matchit
和这些模式,<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>
部分是问题"所在.请注意,定义列表的行为是相同的:matchit 不是跳转到结束标记,而是跳转到中间标记.
我猜想将其粘贴到 HTML ftplugin 中并进行一些自定义会解决问题.
编辑
这一行似乎完全解决了问题:
autocmd FileType html let b:match_words='<:>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
我刚刚删除了 和
的两个完全不必要的模式定义,只留下基本匹配.
I downloaded the Matchit plugin and used it on my HTML file. Everything worked as it was supposed to until I used it on my list.
<ol>
<li id="link-1"><a href="http://www.reddit/">reddit</a></li>
<li id="link-2"><a href="http://www.vim/">vim</a></li>
<li id="link-3"><a href="http://www.w3schools/">w3schools</a></li>
</ol>
If the cursor is on the first o
when I press tab the cursor jumps to the first list item instead of the closing ol
. And when I'm on the l
of the first list item the cursor jumps to the l
of the next list item tag. But if I move the cursor over to the first a of the link tag and hit tab then Matchit works just fine and jumps to the closing tag. Matchit works for all tags but list items? How do I fix this behavior?
For starter, matchit is distributed with Vim without being activated. You don't need to download it, just follow the instructions at :help matchit-install
.
Matchit uses a buffer variable called b:match_words
to define pairs of matching tags: open an HTML file and type echo b:match_words
. The value, here, is:
<:>,<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>
If I understand :help matchit
and these patterns correctly, the <\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>
part is where the "problem" is. Notice that the behaviour is the same for definition lists: instead of jumping to the end tag, matchit jumps to intermediary tags.
I'd guess that pasting this in an HTML ftplugin and doing a bit of customizing would solve the problem.
edit
This line seems to completely resolve the issue:
autocmd FileType html let b:match_words='<:>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
I've just removed the two totally unecessary pattern definitions for <ul|ol>
and <dl>
, leaving only the basic matches.
这篇关于Matchit 跳到 HTML 中的下一个列表项而不是结束标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论