vimtricks.wiki Concise Vim tricks, one at a time.

How do I find which syntax highlighting rules are slowing down Vim?

Answer

:syntime on

Explanation

When Vim feels sluggish while editing files with complex syntax highlighting, :syntime lets you profile exactly which syntax rules are consuming the most time. This is invaluable for diagnosing slow scrolling or input lag in large files with heavy syntax definitions.

How it works

  • :syntime on starts recording timing data for every syntax rule match
  • Edit the file normally — scroll around, type, trigger redraws
  • :syntime report displays a sorted table showing each syntax pattern, how many times it matched, and how much total time it consumed
  • :syntime off stops profiling
  • :syntime clear resets the collected data

Example

:syntime on
" ... scroll through the file, edit text ...
:syntime report

The report output looks like:

TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME
0.123456   5000   3200    0.001234    0.000025  javaScriptComment
0.098765   8000   1500    0.000987    0.000012  javaScriptString
0.045678   2000   800     0.000456    0.000023  javaScriptRegexp

Patterns at the top of the list are the biggest offenders. You can then decide whether to simplify those patterns or switch to a different syntax file.

Tips

  • If a particular regex pattern is extremely slow, consider adding \%l line-number constraints or simplifying the pattern in your custom syntax file
  • For Neovim users, Tree-sitter based highlighting avoids regex-based performance issues entirely
  • Use :syntime clear between tests to get clean measurements

Next

How do I return to normal mode from absolutely any mode in Vim?