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

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

The default directory (/var/tmp) for the vi editing buffer needs space equal to roughly twice the size of the file with which you are working, because 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.

To identify the amount of space left in /var/tmp, use:

  df -k /var/tmp

Following are some possible solutions:

  • Choose another directory for 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, and filename with the name of the file. The /tmp in the third line is an example; you could use other scratch space as vi's editing buffer.

  • To read large files without editing, use other commands that use fewer resources (e.g., less, head, or tail). Although less is the opposite of more, it allows both backward and forward movement in the file. Also, less does not have to read the entire input file before starting; therefore, with large input files, less loads faster than vi.
  • To look at a specified number of lines at the top and bottom of a file, use the head and tail commands, respectively.

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

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

  • Depending on your system, vi may enforce the default maximum line limit of 1,048,560. If the number of lines in your file exceeds this limit, start vi with the -yNumber option, which overrides the maximum line setting. You should set the maximum to twice the number of lines you need, because vi uses the extra lines for buffer manipulation.

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document akqv in the Knowledge Base.
Last modified on 2019-06-18 14:45:26.