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

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.


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.