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

How do I speed up Vim when editing files with very long lines like minified code or CSV?

Answer

:set synmaxcol=200

Explanation

The synmaxcol option tells Vim the maximum column up to which it will apply syntax highlighting on each line. Lines wider than this threshold are only highlighted up to that column — everything beyond is left as plain text. This can give massive performance improvements when editing files with very long lines.

How it works

  • synmaxcol=N — stop syntax highlighting after column N on any line
  • Default value is 3000, which means Vim tries to highlight up to 3000 columns per line
  • Setting it to 200 or 300 covers most normal code while eliminating the cost of parsing extremely wide lines
  • A value of 0 disables the limit entirely (maximum highlighting at any cost)

Example

Add to your vimrc:

set synmaxcol=200

Or set it temporarily in a session:

:set synmaxcol=200

You will notice immediate responsiveness improvements when scrolling through files like:

var a={b:1,c:2,d:3,...};var b=function(x){return x*2+x/3-1...}

Tips

  • Minified JavaScript, CSS, and single-line JSON are the most common culprits for slow syntax performance
  • CSV and TSV files with many columns also benefit significantly
  • You can use :syntime on then scroll through the file and :syntime report to profile which syntax rules are slowest before adjusting
  • For Neovim users with Treesitter, synmaxcol applies to the legacy :syntax engine only; Treesitter has its own performance characteristics

Next

How do I refresh the diff highlighting in Vim when it becomes stale after editing?