Friday, July 10, 2009

Of vim, view and swap files

The view command should run vim in read-only mode. In this mode, vim should not use a swap file. But sometimes, if I am editing a file and open the same file with view in another window, vim complains that the swap file already exists. What's going on?

It turns out that vim does not always run without a swap file when in read only mode. If the file is large enough that more memory than maxmem or maxmemtot is required then a swap file is used even in read-only mode.

On my system (CentOS 5.3 with 2GB RAM) both maxmem and maxmemtot default to 252KB. Many of the source files I edit are larger than this and, therefore, swap files are used even in read-only mode.

By setting maxmem and maxmemtot to something larger, swap files can be avoided for larger files. For example, in your .vimrc file you can add:

set maxmem=1024
set maxmemtot=1024

No comments:

Labels