chenzhiwei
chenzhiwei

Reputation: 461

Vim auto turn off syntax highlighting when a file contains long line

As long lines will slow down Vim when enabled syntax highlighting.

So, can Vim automatically turns off the syntax highlighting when it detects that a file contains a long line?

Upvotes: 1

Views: 999

Answers (2)

Martin Tournoij
Martin Tournoij

Reputation: 27822

In addition to Kent's answer:

  • The 'synmaxcol' setting can control how long Vim will keep looking for syntax. the default is 3000; I set it to 500 in my vimrc.

  • The LargeFile plugin can be used to disable syntax highlighting for large files, which is not exactly what you're asking for, but useful nonetheless.

Upvotes: 6

Kent
Kent

Reputation: 195079

give this a try:

autocmd syntax * 
        \ let a=0+system("wc -L ".expand("%")."|awk '{printf $1}'") |
        \ if a >= XXXX |
        \    syntax off |
        \ endif

change the XXX to a number, which indicates the very long line.

Upvotes: 3

Related Questions