(I think because) Modern computers have a lot more memory, it’s less necessary to have Vim use a swap file. You can disable swapfile creation by adding a line like this to your .vimrc:
set noswapfile
You can see it in action in the Thoughtbot dotfiles:
In ex based editors, the swap file is used to hold the previous state of the file currently being edited. If you say:
$ vim foo
and you get
Swap file “app/views/documents/.foo.swp” already exists!
it means that a previous editing session died (like getting hit with sig 9 or 13) without cleaning up, and is giving you an opportunity to recover the previous state from the vim swap file or delete the swap file. To see it try this:
In one terminal session:
$ vi foo
Hit i and type some text. Stay in command mode and switch to a new terminal window. From that window
$ ps # find your vi session proc
PID TTY TIME CMD
14577 ttys000 0:00.06 vi foo
$ kill -9 14577
and go back to the first terminal window. It will say killed with -9. History up:
$ vi foo # let us see that swap file now
E325: ATTENTION
Found a swap file by the name “.foo.swp”
owned by: some user dated: Before_settling
file name: ~someuser/somepath/foo
modified: YES
user name: some user host name: host
process ID: 14577
While opening file “foo”
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use “:recover” or “vim -r foo”
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “.foo.swp”
to avoid this message.