20

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.

Conner
  • 30,144
  • 8
  • 52
  • 73
Paul Oyster
  • 2,237
  • 3
  • 18
  • 13

5 Answers5

23

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
Paul Oyster
  • 1,228
  • 6
  • 16
  • 19
  • You can probably keep your syntax highlighting if you just change `syntax clear` to `syn sync clear`. It's the syncing that slows you down, although YMMV depending on the syntax involved. Personally, I'm editing an 11 million line IDAPro .LST file with no issues after adding that line. – Orwellophile Jul 24 '16 at 00:15
  • A tip I just discovered to greatly improve the loading time for huge files: disable folding if it has been defined, e.g. `set foldmethod=manual`. – yolenoyer May 14 '20 at 07:20
16

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.

Zathrus
  • 9,948
  • 2
  • 25
  • 22
7

I haven't tried it myself, but the LargeFile plugin seems to be exactly to address the kind of stuff you're looking for.

tomasr
  • 13,683
  • 3
  • 38
  • 30
4

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.

HS.
  • 2,593
  • 2
  • 20
  • 28
0

vim -c 'syntax off' filename.ext