History
Article Edit this page Discussion

Faster loading of large files

From Vim Tips Wiki

Jump to: navigation, search

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 343 Previous Next Created: October 12, 2002 Complexity: intermediate Author: Erik Remmelzwaal Version: 6.0


In the past I experienced long loading times for large files (size over 10MB). These files are normally generated by SQL tracing, XML message based protocols tracing etc. One of the causes of long loading times was syntax parsing, creating swap file etc. Normally one want to view these files and remove not relevant details by deleting lines, but do not want to have undo capabilities and auto recalculation of syntax highlighting.

The code below, I put in my vimrc to switch off a number of defaults for large files.

One can modify the g:LargeFile variable and reload a file to test:

:let g:LargeFile=10
:e
" Protect large files from sourcing and other overhead.
" Files become read only
if !exists("my_auto_commands_loaded")
  let my_auto_commands_loaded = 1
  " Large files are > 10M
  " Set options:
  " eventignore+=FileType (no syntax highlighting etc
  " assumes FileType always on)
  " noswapfile (save copy of file)
  " bufhidden=unload (save memory when other file is viewed)
  " buftype=nowritefile (is read-only)
  " undolevels=-1 (no undo possible)
  let g:LargeFile = 1024 * 1024 * 10
  augroup LargeFile
    autocmd BufReadPre * let f=expand("<afile>") | if getfsize(f) > g:LargeFile | set eventignore+=FileType | setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 | else | set eventignore-=FileType | endif
    augroup END
  endif

[edit] Comments

Can we just set scratch buffer for such purpose? :help special-buffers


File will load faster if you open it read-only: vim -R HugeFile.txt


The Edit large files quickly script is better.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Dark Shadows
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for collaboration of the month.

Send this article to a friend
"Faster loading of large files"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation