echo.mrln.sh /blog /whoami /play
# █

Neovim Syntax Highlighting missing due to long line

2024-02-23

Likely the quick fix:

  • make sure syntax is on at all
  • increase synmaxcol
  • increase maxmempattern
syntax on
set synmaxcol=5000
set maxmempattern=5000

To elaborate

I was writing code for a custom cursor for this blog, when suddenly my (S)CSS file would stop having syntax highlighting.

Syntax highlighting was disabled as soon as I inserted a specific line, that was a lot longer than any other line.

Turning it back on again using syntax on did not yield/give me any results.

Through a quick search/After a little searching I found out there is this variable in (neo)vim called synmaxcol, which sets the maximum number of columns/cols after which syntax highlighting is no longer applied. Note that this only affects the offending/this specific line.

The current value of this variable can be echoed/printed with this command (see the bottom of the terminal window):

set synmaxcol?

In my case, syntax highlighting was disabled for the whole file. Also the line was much shorter than the value of synmaxcol.

I tried to activate syntax highlighting again and to my surprise this time neovim communicated the problem: The maxmempattern value was too low for that file.

So, if you have issues/problems with syntax highlighting not working, try increasing maxmempattern. The error message might just be hiding behind lots of plugin stuff.