I use neovim 0.4.3. When I open a large xml file (about 130-140k lines) syntax highlighting switches off with a message:

'redrawtime' exceeded, syntax highlighting disabled

If add this line to my config init.vim:

set redrawtime=10000

The syntax highlighting works but when I try to scroll up page by page it becomes really slow.

What can be a possible solution or I just need to accept the fact that there is no syntax highlighting for large files in neovim/vim?

  • Do you have g:xml_syntax_folding set? From the comments in the code, "This might slow down syntax highlighting significantly, especially for large files."
    – filbranden
    May 26, 2020 at 20:02
  • I believe @ChristianBrabandt is the maintainer of XML syntax in Vim, so maybe he might know whether this performance issue with large files is expected?
    – filbranden
    May 27, 2020 at 1:01
  • @filbranden No, I don't have g:xml_syntax_folding set.
    – Nurjan
    May 27, 2020 at 6:17

2 Answers 2


Syntax for large files is consistently atrociously slow (especially when the language is hugely recursive à la lisp or xml: C fares much better because it has generally has more consecutive structures than recursive ones). I find it best to turn it off when viewing large documents.

I don’t have anything technical to back this up (links, discussion, timings, etc.), and I would greatly welcome an answer that did.

See also :syntime

One tweak can be bumping up the maxmempattern to let vim use more memory.

  • Looking at $VIMRUNTIME/syntax/xml.vim, I'm not so sure it's that expensive, it doesn't look like it's trying to match tags but only highlight tags, attributes, namespaces, etc. shouldn't be that expensive. There's a comment there about g:xml_syntax_folding making things slower, but that's about it...
    – filbranden
    May 26, 2020 at 20:03
  • 1
    @filbranden i’ve has this issue in clojure before where it seemed that having a lot of forms, even if most of them are shallowly nested (which is rare, granted), causes problems. As i said, I dont have anything to back this up, and I’d love to be wrong => maybe there’s an easy fix
    – D. Ben Knoble
    May 26, 2020 at 20:44
  • I opened the same large xml file in vs code without any problems and the syntax highlighting worked fine. I think there is some specific issue with neovim/vim and it really frustrates me.
    – Nurjan
    May 27, 2020 at 6:46
  • 1
    @Nurjan completely different; Idk what vscode does, but vim’s syntax highlighter is based on regex and a few other things. It’s slow and unwieldy in the long run (though text properties present a new avenue to explore things like tree sitters).
    – D. Ben Knoble
    May 27, 2020 at 12:18

Syntax highlighting is done synchronously in vim, which is why it is slow when dealing with large files.

There's a few highlights you can deactivate to speed things up:

set nocursorline
set nocursorcolumn

You can also set the minimum / maximum highlighted lines (:h :syn-sync-maxlines):

syntax sync minlines=200
syntax sync maxlines=500

There's a good article about this on vim fandom.

A better way to get fast and consistent highlights is to use the language server protocol.

It's not only for highlights though, its first use is indeed completion.

A few vim plugins can use the LSP, here's some of them:

Setting this up can be a bit tedious, but it's very powerful once it's done.

I'm not sure about the others, but CoC offers highlights out of the box.

  • 1
    And with text properties, LSPs can start using true ASTs to build highlighting
    – D. Ben Knoble
    May 26, 2020 at 18:33
  • I use CoC for autocompletion and it's really nice. You're saying that syntax highlighting is done synchronously in vim, but I thought that neovim is more asynchronous in this sense?
    – Nurjan
    May 27, 2020 at 6:48
  • 1
    To be honest, I couldn't say. But through CoC, it should definitely be.
    – Biggybi
    May 27, 2020 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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