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
directorywith the directory that contains the file you wish to edit. The/tmpin the third line is an example; you could use other scratch space as vi's editing buffer. In the last line, replacefilenamewith 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, andtail. Althoughlessis the opposite ofmore, it allows both backward and forward movement in the file. Furthermore,lessdoes 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 thelesscommand, enter: less --helpTo look at a specified number of lines at the top and bottom of a file, use the
headandtailcommands. For more information onheadandtail, 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
splitcommand to split the large file into smaller files before editing in vi: split -l lines filenameIn the above example, replace
lineswith the number of lines you wish in each file, and replacefilenamewith the name of the file you wish to split. - On the Libra Cluster at Indiana University,
since
/var/tmpis 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/tmpYou 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
-yNumberoption. Following is an excerpt from themanpage for-yNumberon 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:
- How do I make the vi editor display or hide line numbers?
- A quick reference list of vi editor commands
Last modified on January 11, 2008.






