Swap file already existst

Hi,

Lately, when I open files in my project, I’m getting lot’s of messages like:

Swap file "app/views/documents/.index.html.erb.swp" already exists!

What is causing this messages to appear and what can I do to prevent it.

Now I just choose the option ‘Delete it’, but to be honest, I’m not sure what I’m doing.

thanks for your help,

Anthony

Anthony,

(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:

Hope this helps.

1 Like

Hi Geoff,

Thanks for the tip. Added the noswapfile setting to my .vimrc file

greetings,

Anthony

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.

Swap file “.foo.swp” already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

In UNIX systems the swap file is used to page memory into and out of. Same name, function unrelated.

1 Like

Hi Jourdan,

Thanks for your excellent explanation of .swp files

greetings,

Anthony