Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

sometime I need to open a several GB log file, now I need to use tail to get suitable part but that is very tedious.

Can I just use vim to open it directly? Currently vim will occupy a lot memory when open a large file... Just wonder why it is required? If there some option can prevent that memory loaded?

share|improve this question

If you just want to have a look at a file, use less.

If you need cut out a specific part of the file, do this (within less):

  1. Go to the 1st page you're interested in

  2. Press the keys m and a - this means: mark position a.

  3. Go to the last position of the file you're interested in

  4. Press the keys | (pipe) and a - this means: pipe everything between here and position a to a command

  5. Type in the command you want the data to be sent to. If you want to copy this data into the editor buffer, just use vim - as command (the minus sign as filename means file to be edited is to be read from stdin).

If you know that you will need all data from a specific position on up to the end of the file you may also do this:

  1. Go to the 1st page you're interested in

  2. Press the keys | (pipe) and $ - this means: pipe everything between here and the end of the file to a command

  3. Type in the command you want the data to be sent to (e.g. cat >/tmp/myfile or vim -).

share|improve this answer
I did not know less could do this. Thanks :) – icedwater Sep 5 '13 at 5:01

Check out this and this.

Basically, your options are:

  1. Give the Vim Large File script a try. It disables certain features to improve Vim's responsiveness when editing large files.
  2. Break the file up to smaller chunks, edit the chunk you care about and concatenate them back together.
share|improve this answer

Yes, Vim can open very large files. But, in order to conserve memory some things you should probably keep in mind before doing so:

  • ignore filetype (no syntax highlighting and so on), although in all probability it won't have syntax highligting for log files at all, but just to be sure so it doesn't start going through them
  • noswapfile (you definitely don't want a copy of a file that size)
  • bufhidden = unload (save memory when other file is viewed)
  • buftype = nowritefile (is read only)
  • undolevels = -1 (no undo possible)

Maybe there is an option or two I missed, but these are so far in my _vimrc.

share|improve this answer
Note that (1) there's a plugin ( for turning on several of these options automatically when a large file is opened, and (2) even with this program, opening files that are more than a couple GB in size can still be problematic, so I recommend following the "Ctrl-C" tip here: – Kyle Strand Oct 29 '14 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .