Indiana University
University Information Technology Services
  
What are archived documents?

When using vi to edit a large file, what should I do if I get the "not enough space" error message?

The default directory (/var/tmp) for the vi editing buffer needs roughly twice the size of the file you are working with, since vi uses the extra lines for buffer manipulation. If the /var/tmp directory does not have enough space for the editing buffer (e.g., you are working with a large file, or the system is running out of space), you will receive the following error message:

"Not enough space in /var/tmp."

Following are some possible solutions:

  • One approach is to choose a different directory as vi's editing buffer: cd directory vi :set directory=/tmp :e filename

    In the above example, replace directory with the directory that contains the file you wish to edit. The /tmp in the third line is an example; you could use other scratch space as vi's editing buffer. In the last line, replace filename with the name of the file you wish to edit.

  • To read large files without editing, you can use other commands that use fewer resources, such as less , head , and tail . Although less is the opposite of more , it allows both backward and forward movement in the file. Furthermore, less does not have to read the entire input file before starting; thus, with large input files, it starts up faster than vi. For information on how to use the less command, enter: less --help

    To look at a specified number of lines at the top and bottom of a file, use the head and tail commands. For more information on head and tail , see the man pages.

  • Running vi on a file larger than 64MB might generate an error, depending on your system. In that case, use the split command to split the large file into smaller files before editing in vi: split -l lines filename

    In the above example, replace lines with the number of lines you wish in each file, and replace filename with the name of the file you wish to split.

  • On the Libra Cluster at Indiana University, since /var/tmp is usually on local disk (in contrast to being NSF-mounted like your home directory), you can simply log into a different node that has plenty of space (roughly twice the size of the file) in /var/tmp, and then use vi to edit the file. To identify the amount of space left in /var/tmp, use the following command: df -k /var/tmp

    You should get results something like the following:

    Filesystem 512-blocks Free %Used Iused %Iused Mounted on /dev/hd9var 131072 75072 43% 836 6% /var
  • Also on Libra at IU, by default, vi enforces the upper limit of 1,048,560 lines. If you have a file that has more lines than this, then you need to change this default value by starting vi using the -yNumber option. Following is an excerpt from the man page for -yNumber on Libra:

    "-yNumber Overrides the maximum line setting of 1,048,560 with any value greater than 1024. You should request twice the number of lines that you require because the vi editor uses the extra lines for buffer manipulation."

This document was developed with support from the National Science Foundation (NSF) under Grant No. 0503697 to the University of Chicago and subcontracted to Indiana University. Additional support was provided by IU through its participation in the TeraGrid, which is supported by the NSF under Grants No. 0833618, SCI451237, SCI535258, and SCI504075. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.

Also see:

This is document akqv in domains all and tgrid-all.
Last modified on January 11, 2008.
Please tell us, did you find the answer to your question?