Vim logo vim online Vim Book Ad

 Tip #343: Faster loading of large files

 tip karma   Rating 21/12, Viewed by 1210 

created:   October 12, 2002 11:32      complexity:   intermediate
author:   Erik Remmelzwaal      as of Vim:   6.0

In the past I experienced long loading times for large files ( size > 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

It would be interesting to know if others have more or better suggestions.

" 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

 rate this tip  Life Changing Helpful Unfulfilling 

<<Remap <ESC> | Cut / Copy / Delete / Paste Lines without knowing the number of lines >>

Additional Notes

[email protected], October 13, 2002 18:50

Can we just set scratch buffer for such purpose?

help special-buffers

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo