vim 拼写检查 - 仅在 LaTeX 文件中添加注释
我使用 gvim 编辑 LaTex .tex 文件。我注意到它只检查注释文本的拼写。如果我在常规文本中出现错误 - 没有下划线。如果我用 % 注释此文本,拼写错误会立即带有下划线。怎么了?是不是有什么奇怪的选项被打开了?
I use gvim to edit LaTex .tex file. I noticed that it checks spelling on the fly only for the commented text. If I have a mistake in a regular text - no underline. If I comment this text with % , the misspell is underlined immediately. What is wrong? Is there any strange option turned on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
Latex ft 插件方便地定义了这种行为。
SpellChecker : 拼写检查文本,包括 LaTeX 文档
使用 Latexmk、vim 拼写检查和 vim Latex-suite
有一个选项似乎很接近:
Update
Also
has very important tidbits ,就像
你必须弄清楚是否可以使用它/从那里推断
The latex ft plugin conveniently defines this behaviour.
SpellChecker : Spell check text including LaTeX documents
Using latexmk, vim spell checking and vim latex-suite
There is an option that appears to come close:
Update
Also
has very useful tidbits, like
You'll have to figure out whether you can use that/extrapolate from there
我有同样的问题(VIM 7.3),但是 vim-latex-devel 邮件列表中的这篇文章 提供了线索。为了让拼写检查工作,我必须放入
我的
~/.vimrc
,但是它必须在之后声明才能
工作。
I had the same problem (VIM 7.3), but this post at the vim-latex-devel mailing list provided the clue. To get the spell checking working, I had to put
in my
~/.vimrc
, but it has to be declared afteror
for it to work.
我不知道这是否是一个粗略的黑客和预期的解决方案,但我创建了一个名为 .vim/after/syntax/tex.vim 的文件
包含单行:
现在 vim 拼写检查命令之间的普通文本和作为参数传递的文本,因为你无法在语法上区分它们:
因此,它在我的序言中检查太多。但我把它放在另一个文件中,所以我不在乎。
I don't whether this is a crude hack and the intended solution, but I created a file called .vim/after/syntax/tex.vim
containing the single line:
Now vim spell checks the normal text between the commands and the text passed as parameters, because you cannot differentiate them syntacticly:
Hence, it checks way too much in my preamble. But I have it located in another file, so I don't really care.
处理主文档中包含的文件时经常会出现此问题。
如果您打开的 TeX 文件将被包含并且不包含节、章节、
\begin{document}
...,您可以通过添加%begin-include< 来标记它/code> 在文件顶部。这样,vim 会将文件内容识别为 texDocZone
区域的一部分,从而启用拼写检查。使用
%end-include
,您可以设置texDocZone
的结尾。此行为似乎没有记录,但在 vim 语法文件中进行了描述: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim
tl;dr: 添加
%begin-include< /代码>到你的 tex 文件的顶部。
This problem often occurs when working with files which are included by a master document.
If you are opening a TeX file which will be included and does not contain a section, chapter,
\begin{document}
, ... you can mark it by adding%begin-include
at the top of the file. This way vim recognizes the file content as being part of thetexDocZone
region, which enables spellchecking.With
%end-include
you can set the end of thetexDocZone
.This behavior seems not to be documented, but is described in the vim syntax file: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim
tl;dr: Add
%begin-include
to the top of your tex file.我遇到了同样的问题——我的书第一章的 .tex 文件拼写检查正常,但第二章的文件只会对注释进行拼写检查。发生这种情况显然是因为 vim 没有查看足够多的上下文行并感到困惑。 Ingo Karkat 的解决方案此处为我解决了这个问题。具体来说,我使用了:
在 ~/.vim/after/syntax/tex.vim 中
I encountered the same problem -- the .tex file for the first chapter of my book spell checked normally, but the file for the second chapter would only spell check the comments. This apparently happens because vim isn't looking at enough lines of context and gets confused. Ingo Karkat's solution here fixed it for me. Specifically, I used:
in ~/.vim/after/syntax/tex.vim
tldr;不要将
\section
命令放入您的主.tex
文档我也做了同样的观察,我也会坚持“以前,它有效,但我没有”不改变任何东西”。
然后我观察到,这种不需要的行为仅发生在
.tex
文档中,其中我有一个master.tex
,包含 章节作为单独的chapterx .tex
文件。此外,如果所有\section
定义都在chapterx.tex
中并且 NOT 在master.tex 中,则一切正常
。否则,正如我所想,vim语法和拼写检查例程很难确定它们位于哪个区域,参见。这个问题 Vim 拼写检查并不总是在 .tex 文件中工作。检查 Vim 中的区域
tldr; don't put
\section
commands in your master.tex
documentI made the same observation and I also would insist on "before, it worked and I didn't change anything".
Then I observed that this unwanted behaviour only occurred in
.tex
documents where I have amaster.tex
that includes chapters as separatechapterx.tex
files. Moreover, everything works fine if all the\section
definitions are in thechapterx.tex
's and NOT in themaster.tex
.Otherwise, as I think, the vim syntax and spell checking routines have a hard time determining in which region they are, cf. this question Vim spellcheck not always working in .tex file. Check region in Vim
我发现了同样的问题,但解决方案不同。在某些 .tex 文件中,拼写检查按预期工作,而其他文件则不然 (documentclass{scrlttr2})。只有在评论中的单词才带有下划线......因此我比较了一份工作和一份不工作的 .tex 文档的标题。我发现了一个令人惊讶的 texblock,它阻碍了文档本身的拼写检查:
而这段代码只是我之前编辑过的不同司法文本的“残留”。将其注释掉,在信件文档中设置正常的拼写检查并突出显示文本。 (MacVim 8.1 Latex 套件 macOS 10.13.6 vim-latex v1.10.0)
I found the same problem, but a different solution to it. In some .tex files the spell-check was working as expected others not (documentclass{scrlttr2}). Only in the comments words were underlined ... So I compared the headers of one working and one not working .tex document. I found a surprisingly texblock, which were hindering the spell check in the document itself:
And this code was only an "hangover" of a different juridical text, I edited before. Commenting it out, set the normal spell-check with high-lighted texts in the letter document. (MacVim 8.1 latex-suite macOS 10.13.6 vim-latex v1.10.0)
这里的答案都不适合我,但我可以看到如果我在 vim 中输入
syntaxpell
作为命令,它会起作用。事实证明,这是因为没有自动为 tex 文件类型设置语法,我找到了解决方案
None of the answers here worked for me, but I could see if I typed
syntax spell
as a command in vim it would work.It turns out it was because syntax wasn't being set for the tex filetype automatically, and I found the solution here.