Kristian Kristian - 1 year ago 104
LaTeX Question

Vim spellcheck not always working in .tex file. Check region in Vim

I use Vim to write my

files, but I am having trouble with the spell checker in Vim. Sometimes it does not check the words, and I think that it might be for the following reason.

Since Vim is clearly not supposed to check all of the words in the
document, for example, not the preamble, it only check spelling in certain regions (in the syntax sense). As I have gathered from here, one of these regions is
. These regions can become quite large, indeed a section often is, so Vim is having trouble realising that it actually is in a
region (or in ay other), and therefore does not check the spelling. This can happen if I make a search in the document, or any kind of jump that skips multiple lines (or rather pages).

The way that I concluded this might be the reason is the following: I know that the command

:echo synIDattr(synID(line("."),col("."),1),"name")

prints the name of the region/regions you are in (I found it here), so when the spell checker did not work I tried this, and it told me that it was not in any region at all. The places it did work, I was in a region where it ought to check the spelling.

So far my only solution is to find the nearest section above the point I want the speller to check, and then manually move the cursor back down to the given point.

Ideally I would very much like a solution that ensures that this does not happen, but I would also settle for a way to manually make vim 'update' which region it is in, without me having to move the cursor a lot. In the latter case I am thinking of a solution which could be made to a shortcut.

PS I was in doubt about what to call the question. If you come up with a title which explain the problem better, fell free to change it.

Answer Source

syntax/tex.vim already uses quite elaborate sync patterns to ensure that the syntax highlighting is accurate, but for long and complex documents, this may still fail.

Best you can do is trying to increase both values of

syn sync maxlines=200
syn sync minlines=50

(e.g. to 2000 and 500). Put this in ~/.vim/after/syntax/tex.vim to override the defaults.

syntax sync fromstart

might give the best results, but may be too slow. You'll find a description of syntax syncing at :help :syn-sync.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download