0

The highlighting of misspelled words in my LaTeX documents breaks, when I open a .tex file and jump to the bottom instead of scrolling through the whole document. Only .tex files seem to be affected, so it might be an issue with vim-latex (version 1.10.0), which I am using. When editing large .txt files the problem does not seem to occur.

I first thought it might be an issue with the colourscheme that I am using, but the problem persists, when using the default one. I have also tried different terminal emulators to run vim in - but to no avail.

Further, I have noticed that when pressing Ctrl-L when being lower than a certain line the syntax highlightling disappears. Only when scrolling almost to the top and scrolling back down the highlights show again. Maybe something in the LaTeX source triggers the problem as the problem only occurrs after a certain point, but so far I was not able to find it.

I am using the following vim version

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun 17 2021 23:53:31)
Included patches: 1-814
Modified by Gentoo-8.2.0814-r100
...

and this .vimrc.

Does anybody here have an idea where the problem could lie?

EDIT: Ok, I figured out how to exactly reproduce the problem (it is indeed something in the LaTeX source that triggers the problem). It definitely looks like a bug, but maybe there is a workaround - also I wonder, whether other people are able to reproduce it.

Steps to reproduce:

  • Create the follwing file issue.tex:
%\end{center}
\begin{document}

% ... 130 BLANK LINES and one misspelled word on one line ...

\end{document}
  • Resize the window of your terminal emulator such that you can see 49 lines at once.

  • Now scroll down such that the misspelled (and highlighted) word is visible but that line 126 is outside the buffer. Press Ctrl-L (nothing should happen). Now scroll down such that line 126 is in sight. Press Ctrl-L (the highlight should disappear).

With this setup the problem occurs exactly then, when the lines below (and including) 125 lines after the occurrence of \end{center} are visible in the buffer.

When resizing the window, I realised that when the buffer has only a height of 21, the issue happens already after (and including) line 98. For height 38, the corresponding problematic line is 115.

To summarise: If \end{center} appears anywhere in the document and lines after and including line (line number of \end{center}) + (buffer height) + 77 are visible, pressing Ctrl-L clears the highlights. Moving to the top and scrolling down restores them.

When renaming the file to issue.txt (such that vim-latex is not used) and reopening it, the problem disappears.

Sorry for this long post, I know this would probably rather be a case for a bug report, but so far I'm not sure actually whether it's a bug related to vim or the plugin (also the plugin does not seem to be actively maintained).

If anybody could try to reproduce this and has an idea for a workaround (besides getting rid of \end{center}), it would be appreciated.

EDIT: \end{enumerate} and \end{itemize} also seem to trigger the problem, whereas \end{align} does not do so.

4
  • 1
    Vim will abort syntax highlighting when it takes longer than the configured time limit which is stored in 'redrawtime'. (Though, I'd think you'd get a warning to that effect.) This usually happens in files with high-complexity parsing. Try increasing that and see if it helps with spelling highlighting.
    – B Layer
    Jul 29 at 19:43
  • Unfortunately that does not fix it. I've changed the redrawtime from 2000 to 10000, but the problem persists.
    – greg.
    Jul 29 at 19:46
  • Bummer. Not sure then what the problem might be. I wonder if there's a separate setting for spelling timeout...
    – B Layer
    Jul 29 at 19:47
  • You can also issue a command (:syntax sync or something to that affect to force a recomputation that usually works
    – D. Ben Knoble
    Jul 29 at 20:53
0

As D. Ben Knoble correctly suggested, the problem was indeed related to incorrect syntax synchronisation. Even though putting syntax sync fromstart in the .vimrc does not solve the problem, adding the following to the .vimrc fixes the issue:

autocmd BufNewFile,BufRead *.tex syntax sync fromstart

I suppose vim-latex overwrites the syntax sync setting otherwise.

2
  • You can't put in your vimrc because it's not a global thing. Each syntax gets its own synchronization rules. You'd be better off using a local after/ftplugin or after/syntax extension for this (:help runtimepath), or at least autocmd FileType tex
    – D. Ben Knoble
    Aug 3 at 18:10
  • Ah, awesome! Thank you very much for the feedback!
    – greg.
    Aug 6 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.