Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid syntax-highlighting for large files in vim?

Tags:

Huge files take forever to load and work with in vim, due to syntax-highlighting.

I'm looking for a way to limit size of highlighted files, such that files larger than (say) 10MB will be colorless.

like image 467
Paul Oyster Avatar asked Oct 07 '08 12:10

Paul Oyster


People also ask

Can vim open large files?

Vim can handle large files pretty well. I just edited a 3.4GB file, deleting lines, etc. Three things to keep in mind: Press Ctrl-C: Vim tries to read in the whole file initially, to do things like syntax highlighting and number of lines in file, etc.

How do I permanently set syntax in Vim?

Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open . vimrc file, change the text “syntax on” to “syntax off” and save the file.

Why are some words highlighted in vim?

Most filetypes (like python) in Vim come with a syntax that defines highlight groups (see them via :highlight ). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic, for terminals, color terminals, and/or GVIM.


1 Answers

Adding the following line to _vimrc does the trick, with a bonus: it handles gzipped files, too (which is a common case with huge files):

autocmd BufWinEnter * if line2byte(line("$") + 1) > 1000000 | syntax clear | endif
like image 137
Paul Oyster Avatar answered Oct 04 '22 22:10

Paul Oyster