How to avoid syntax-highlighting for large files in vim?
-
05-07-2019 - |
Question
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.
Solution
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
OTHER TIPS
Add to your .vimrc:
autocmd BufReadPre * if getfsize(expand("%")) > 10000000 | syntax off | endif
Note that this disables syntax highlighting in ALL buffers; syntax is a global vim thing and cannot be restricted to a single buffer.
I haven't tried it myself, but the LargeFile plugin seems to be exactly to address the kind of stuff you're looking for.
vim -u NONE <filename>
This will skip all initializations from configuration files.
Use uppercase U when running gvim.
"-i NONE" does only exclude viminfo from being loaded. If you defined syntax hilighting in there, that would help too.
vim -c 'syntax off' filename.ext