Skip to main content
Add code from the link; so it's not a link-only answer anymore
Source Link

Vim is the wrong tool for the job: you should use a pager like more or less.

If you insist on using an editor, try this tip onexample adapted from the Vim wiki.:

augroup LargeFile
        let g:large_file = 10485760 " 10MB

        " 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)
        au BufReadPre *
                \ let f=expand("<afile>") |
                \ if getfsize(f) > g:large_file |
                        \ set eventignore+=FileType |
                        \ setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 |
                \ else |
                        \ set eventignore-=FileType |
                \ endif
augroup END

Vim is the wrong tool for the job: you should use a pager like more or less.

If you insist on using an editor, try this tip on the Vim wiki.

Vim is the wrong tool for the job: you should use a pager like more or less.

If you insist on using an editor, try this example adapted from the Vim wiki:

augroup LargeFile
        let g:large_file = 10485760 " 10MB

        " 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)
        au BufReadPre *
                \ let f=expand("<afile>") |
                \ if getfsize(f) > g:large_file |
                        \ set eventignore+=FileType |
                        \ setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 |
                \ else |
                        \ set eventignore-=FileType |
                \ endif
augroup END
Source Link
romainl
  • 42.3k
  • 5
  • 87
  • 118

Vim is the wrong tool for the job: you should use a pager like more or less.

If you insist on using an editor, try this tip on the Vim wiki.