如何改变vim拼写中的单词识别?

发布于 2024-08-01 16:09:15 字数 348 浏览 3 评论 0原文

我喜欢 vim 7.0 通过 :setpell 支持拼写检查,而且我喜欢它默认只检查 C 代码中的注释和文本字符串。 但我想找到一种方法来改变行为,以便 vim 知道当我编写包含下划线的单词时,我不希望检查该单词的拼写。

问题是我经常会在注释中引用变量或函数名称,所以现在 vim 认为每一段不是完整正确单词的文本都是拼写错误。 例如。

/* 变量 proj_abc_ptr 用于函数 do_func_stuff' */

大多数时候,下划线分隔的部分是完整的单词,但其他时候它们是缩写,我不希望添加到单词中列表。 有没有全局方法告诉 vim 在拼写检查时将 _ 作为单词的一部分包含在内?

I like that vim 7.0 supports spell checking via :set spell, and I like that it by default only checks comments and text strings in my C code. But I wanted to find a way to change the behavior so that vim will know that when I write words containing underscores, I don't want that word spell checked.

The problem is that I often will refer to variable or function names in my comments, and so right now vim thinks that each piece of text that isn't a complete correct word is a spelling error. Eg.

/* The variable proj_abc_ptr is used in function do_func_stuff' */

Most of the time, the pieces seperated by underscores are complete words, but other times they are abbreviations that I would prefer not to add to a word list. Is there any global way to tell vim to include _'s as part of the word when spell checking?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乞讨 2024-08-08 16:09:15

以下是一些要放入 .vim/after/syntax/{LANG}.vim 文件中的更通用的拼写检查异常规则:

" Disable spell-checking of bizarre words:
"  - Mixed alpha / numeric
"  - Mixed case (starting upper) / All upper
"  - Mixed case (starting lower)
"  - Contains strange character
syn match spellingException "\<\w*\d[\d\w]*\>"      transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\u\l*\)\{2,}\>"    transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\l\+\u\+\)\+\l*\>" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\S*[/\\_`]\S*"         transparent contained containedin=pythonComment,python.*String contains=@NoSpell

pythonComment,python.*String 更改为您的语言。

  • transparent 意味着匹配从包含块继承其突出显示属性(即这些规则不会更改文本的显示方式)。
  • contained 防止这些匹配超出包含块(最后一条规则以 \S* 结尾,这可能会匹配超出块的末尾)
  • containedin 保存要添加这些新规则的现有语法组的列表。
  • contains=@NoSpell 覆盖所有继承的组,从而告诉拼写检查器跳过匹配的文本。

Here are some more general spell-checking exception rules to put in .vim/after/syntax/{LANG}.vim files:

" Disable spell-checking of bizarre words:
"  - Mixed alpha / numeric
"  - Mixed case (starting upper) / All upper
"  - Mixed case (starting lower)
"  - Contains strange character
syn match spellingException "\<\w*\d[\d\w]*\>"      transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\u\l*\)\{2,}\>"    transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\l\+\u\+\)\+\l*\>" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\S*[/\\_`]\S*"         transparent contained containedin=pythonComment,python.*String contains=@NoSpell

Change pythonComment,python.*String for your language.

  • transparent means that the match inherits its highlighting properties from the containing block (i.e. these rules do not change the way text is displayed).
  • contained prevents these matches from extending past the containing block (the last rule ends with \S* which would likely match past the end of a block)
  • containedin holds a list of existing syntax groups to add these new rules to.
  • contains=@NoSpell overrides any and all inherited groups, thus telling the spellchecker to skip the matched text.
梦醒灬来后我 2024-08-08 16:09:15

您需要将其移至其自己的组中。 像这样的事情:

hi link cCommentUnderscore cComment
syn match cCommentUnderscore display '\k\+_\w\+'
syn cluster cCommentGroup add=cCommentUnderscore

在某些荧光笔中,您可能需要在匹配行末尾使用 contains=@NoSpell ,但在 C 中,默认值为 @NoSpell ,所以应该是就这样就好了。

You'll need to move it into its own group. Something like this:

hi link cCommentUnderscore cComment
syn match cCommentUnderscore display '\k\+_\w\+'
syn cluster cCommentGroup add=cCommentUnderscore

In some highlighters you may need contains=@NoSpell on the end of the match line, but in C, the default is @NoSpell, so it should be fine like that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文