Swap file ".file.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:
I usually see this message when I accidentally :edit
the wrong file, i.e., one which I'm already editing in another terminal. My preferred solution in this case would be to tell Vim: oops, that was a mistake, please do nothing.
Both [Q]uit
and [A]bort
work, but they also add the file to the buffer list. I usually have a number of buffers open and page through them with the F3 and F4 keys, which I have mapped to :up
plus :bp
and :bn
, respectively. This means I have to manually :bd
the accidentally added file.
This happens often enough that it's becoming annoying, and for some reason I don't seem to be learning from repeating this particular mistake. Is there a way to avoid adding the file to the buffer list? If not, what would be a good way to automate "delete the last opened buffer"?
Related: