Vimtex: Slowdown in 500 line file caused by highlighting of environment begin/end commands

Created on 6 Aug 2016  路  22Comments  路  Source: lervag/vimtex

I am working on a ~500 line LaTeX file and am currently experiencing very noticeable lag when scrolling. I have not included a minimal working example as this only seems to happen when the file grows larger.

The issue persisted when I disabled vimtex so it is not the fault of the inbuilt vim plugin. It seems to be related to the highlighting of \begin{} and \end{} environment commands.

Is there a way to disable this highlighting to confirm if it is the problem? And if it is, then is there anything I can do about it except keep my files shorter?

All 22 comments

Can you reproduce this with a minimal vimrc file and post it here?

How long lines are you using?

Vimtex should work fine with long LaTeX files, so I am expecting that this might be due to folding. If you use folding, but do not use either FastFold or the manual fold mode, then it is a common issue that things get slow, see :h vimtex-folding.

Please also see: #459 #372

I have the same issue. Everything else is quite fast and I have no issue (toggling toc, viewing labels, etc) but highlighting \begin \end environment causes a noticeable lag. Tried with both neovim and vim and the result is the same. ~500 lines text with short lines (80 characters max).

Ok. I don't have this issue. Thus, in order to work on this, I need a minimal example. Please provide one, or I can't help.

Ok, I spent a bit tweaking my settings because I noticed that I don't get the lag with minimal vimrc and it seems that setting visual cursorline set cursorline is the trigger to the lag I'm getting.

P.S. great work with this, I'm really enjoying this plugin so far!

Thanks!

And strange, I also use set cursorline, but I still don't get the lag. If you can use a minimal example that does reproduce this, please let me know. I can try to find a solution.

I'm also getting a large lag when I roll over \begin{} \end{} pairs. Turning off cursorline improves it a bit, but there is still a small delay. The first commit with the problem is a80a260.

If I get the chance, I will try to construct a minimal example.

I have the problem with this file with the vimrc

set nocompatible
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'lervag/vimtex'
call vundle#end()
filetype plugin indent on
syntax on
set cursorline

I can reproduce the issue with @widdma's example above. In that case the lag is still present with cursorline not set but much less bad.

With my own file, the lag is very noticeable even though I never enabled cursorline before. I will try to produce a minimum working example showing the lag without cursorline enabled tomorrow.

As others have said, thanks so much for this plugin @lervag -- the best Vim LaTeX plugin I've used!

There, I think I solved it. Please test.

And thanks for the kind words! :)

That's much better for me. Thanks for the quick response and the great work!

No problem! Turns out that the regexes were way to complicated. Thanks for noticing and reporting!

Solved it for me too. Rock on!

Is there any way of completely disabling the highlighting? I'd rather not have any highlighting as I don't need it and it causes my cursor to move slowly.

Yes, you can do syntax off. If you don't want syntax highlighting in general, you can add this to your vimrc file. If you only want to disable syntax highlighting in LaTeX files, you can add an autocommand to your vimrc file, e.g.:

augroup MyVimrcAutocmds
  autocmd!
  autocmd FileType tex syntax off
augroup END

It is not my intention to disable the entire syntax highlighting. It is only the mutual highlighting of the begin and end tags that slow down my cursor, so I was asking if there is a feature to disable only those. My documents can get well into the 1000s of lines, so it is necessary.

That was not what you asked. Please be more specific when you formulate your questions.

My documents can get close to 10 000 lines, and I don't really have a problem. Just FYI.

However, you can disable e.g. matching delimiter highlighting, see :h g:vimtex_matchparen_enabled. You can also make syntax faster with the g:tex_fast option, see :h g:tex_fast.

Thanks for the assistance. I'm not using a very powerful computer for my latex note taking activity.

I assumed that raising this question in context of the previous begin and end highlighting discussion would be sufficient to imply the same context, but it should have been more clear.

No problem. I can understand that the context could be taken into account; I didn't quite read the backlog/context before replying. In any case, I hope my pointers will help improve the speed. :)

Yes, the g:vimtex_matchparen_enabled option exactly fixed it, thanks :)

@lervag I have the exact issue as OP. I work mostly with math stuffs in latex, so I will have a a fair number of \begin{align} and end{align} in my document.

The highlighting matched open close environment and especially matching \left( \right) etc was a nice feature to have. Now that I disabled it g:vimtex_matchparen_enabled=0 there is no lag while scrolling but had to sacrifice this useful feature. Any chance you could make it work (remove scroll lag) without disabling this feature (highlight match)?

These environments are mostly indented in my latex file. So one workaround that I have been using is to place the cursor on the first column of document (because its mostly spaces) whenever I have to scroll, so that the cursor never passes over the begin close stuffs and the scroll is smoother, but it is kind of annoying to remember to 0 before scrolling.

I also work with documents that contain a lot of math, and I don't have these issues. And so, it is difficult to debug the problem.

However, you should note that there now exists a dedicated plugin that works for several file types:

Plug 'andymass/vim-matchup'

https://github.com/andymass/vim-matchup

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chakravala picture chakravala  路  5Comments

siemdejong picture siemdejong  路  5Comments

thomasahle picture thomasahle  路  4Comments

krissen picture krissen  路  5Comments

sharethewisdom picture sharethewisdom  路  3Comments