Ubuntu – Can’t save .bashrc file in VIM (“The swap file ”.bashrc.swp“ already exists!”)

vim

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:

Best Answer

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.

Related Question