简体   繁体   English

在 vimrc 中设置拼写异常

[英]Set spelling exception in vimrc

When editing a text in markdown, I don't want to highlight bibliography entries.在 Markdown 中编辑文本时,我不想突出显示参考书目条目。 This can be achieved with the following command:这可以通过以下命令来实现:

:syn match CitNoSpell '\[@[^[:space:]]\+\]' contains=@NoSpell

However, if I enter this command to .vimrc , it is ignored.但是,如果我将此命令输入到.vimrc ,则会被忽略。 I assume that is because spell file is loaded after vimrc has been read, and this definition is not kept.我认为这是因为在读取 vimrc 之后加载了拼写文件,并且没有保留此定义。

How should I force vim to ignore this pattern?我应该如何强制 vim 忽略这种模式? I prefer it to stay in .vimrc, as I synchronize the file across multiple systems, but another solution would also be welcome.我更喜欢它保留在 .vimrc 中,因为我跨多个系统同步文件,但也欢迎使用另一种解决方案。

As the ~/.vimrc is loaded first (before any files), the syntax of an opened file is set only later, and syntax scripts :syntax clear any existing syntax stuff, including your definition.由于~/.vimrc首先加载(在任何文件之前),打开文件的语法仅在稍后设置,语法脚本:syntax clear任何现有的语法内容,包括您的定义。

The right place for your customization would be the :help after-directory ;自定义的正确位置是:help after-directory ie ~/.vim/after/syntax/markdown.vim , as this will be sourced after $VIMRUNTIME/syntax/markdown.vim .~/.vim/after/syntax/markdown.vim ,因为这将在$VIMRUNTIME/syntax/markdown.vim

If you insist on configuring this within your ~/.vimrc , you can try the following autocmd, which has to be put somewhere after :syntax on :如果你坚持在你的~/.vimrc配置它,你可以尝试下面的 autocmd,它必须放在:syntax on之后的某个地方:

autocmd Syntax markdown syn match CitNoSpell ...

PS: For consistency, as you're tweaking the Markdown syntax, your added syntax group should also start with the syntax name, ie markdownCitNoSpell . PS:为了保持一致性,当你调整 Markdown 语法时,你添加的语法组也应该以语法名称开头,即markdownCitNoSpell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM