Can't save .bashrc file in VIM ("The swap file ".bashrc.swp" already exists!")

I have problem with .bashrc file I can't save changes by command :wq. When I put command to terminal vim .bashrc I have message like below. And when I choose "Edit" I am in .bashrc but :wq isn't save and close file

E325: ATTENTION
I found a swap file named ".bashrc.swp" owned by browsers Date: Thu Feb 18 11:05:15 2016 file name: darek ~ / .bashrc changed: YES Member: darek host name: darek-SATELLITE-L850-1LE Process ID: 5119
When opening the file ".bashrc" Date: Tue Feb 16, 2016 8:42:37 p.m.
(1) Another small program 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 so, use ": recover" or "vim -r .bashrc" to recover the changes (see ": help recovery)"). If you've already done so, you remove the swap file ".bashrc.swp" to avoid this message.
The swap file ".bashrc.swp" already exists!
[O] create Read-Only, (E) dit although Re (d) create (D) elete (E) xit, (R) eject:
1

2 Answers

You probably exited editing that file in a way such that the system did not finish saving it.

Easy solution: remove the swap file as shown in the message " If you've already done so, you remove the swap file ".bashrc.swp" to avoid this message."

Do a

ls -la .bashrc.swp

to confirm its existence and remove the file it shows with rm .bashrc.swp.

3

Swap files store changes you've made to the buffer. If Vim or your computer crashes, they allow you to recover those changes. Swap files also provide a way to avoid multiple instances of Vim from editing the same file. source

.bashrc.swp existence suggest that your vim session was terminated abnormally, may be crashed, killed it without closing, putty session lost etc.

This is the vim way of telling that you can recover your unsaved changes. Theory apart, there are multiple ways to fix the irritation notice.

vim bashrc then R to recover. After recovering, oh yes the fun part starts now,

:e!

Then the same dialogue will come. This time, you select D to delete the swap file.

Secondly, you can delete .bashrc.swp by using `rm -f .bashrc,swp.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like