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
200or300covers most normal code while eliminating the cost of parsing extremely wide lines - A value of
0disables 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 onthen scroll through the file and:syntime reportto profile which syntax rules are slowest before adjusting - For Neovim users with Treesitter,
synmaxcolapplies to the legacy:syntaxengine only; Treesitter has its own performance characteristics