23

When I try to open a file from multiple vim instances, I get an error with several options:

Swap file "~/.vim/tmp/file.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

What is the difference between "Quit" and "Abort"?

My first guess was, when I'm trying to open multiple files and only one is being edited elsewhere, "quit" may skip that one and "abort" quit the program, but that is evidently incorrect -- both just abandon the whole attempt at editing and drop back to the terminal.

  • 2
    Does :help swap-exists-choices answer your question? – FDinoff May 12 '15 at 3:27
  • @FDinoff it helps, but I'm not quite clear on "Abort" still. "also abort further commands. This is useful when loading a script that edits several files" - Are the "further commands" supposed to be from a vim script? Is it really common enough for a vim script to open new buffers that this is a concern? – Kevin May 12 '15 at 3:44
19

Try this: run vim file1 in a terminal, then run vim -p file1 file2 in a different terminal. The second command will prompt you as above. If you answer Quit, you still get to edit file2. If you answer Abort you just quit Vim, thus "aborting any further commands".

  • So is there only a difference when opening in tabs or split windows (-p/-o/-O)? Just using vim file1 file2 exits entirely on both quit and abort when file1 is being edited; and when file2 is being edited, the prompt doesn't appear until hitting next, and in that case both quit and abort just drop back to file1. – Kevin May 12 '15 at 17:46
  • 1
    You don't understand. Opening files is essentially a sequence of commands. vim file1 file2 does two things: it sets the arguments (the thing you can access with argv()), and it loads the first file in the buffer. The second file is actually loaded only when you run :n (or similar). When Vim prompts you the arguments have already been set, so if you Quit at that point there is no "further" command left to run. Also, other things count as commands too, f.i. autocmds and commands set with vim -c. You should think all this in terms of commands, not in terms of affected files. – lcd047 May 12 '15 at 18:23
4

@FDinoff suggested checking the vim help. In case anyone wanted to see these more easily:

WHAT TO DO?                                     *swap-exists-choices*

If dialogs are supported you will be asked to select one of five choices:

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

O  Open the file readonly.  Use this when you just want to view the file and
   don't need to recover it.  You might want to use this when you know someone
   else is editing the file, but you just want to look in it and not make
   changes.

E  Edit the file anyway.  Use this with caution!  If the file is being edited
   in another Vim, you might end up with two versions of the file.  Vim will
   try to warn you when this happens, but better be safe then sorry.

R  Recover the file from the swap file.  Use this if you know that the swap
   file contains changes that you want to recover.

Q  Quit.  This avoids starting to edit the file.  Use this if there is another
   Vim editing the same file.
      When you just started Vim, this will exit Vim.  When starting Vim with
   files in several windows, Vim quits only if there is a swap file for the
   first one.  When using an edit command, the file will not be loaded and you
   are taken back to the previously edited file.

A  Abort.  Like Quit, but also abort further commands.  This is useful when
   loading a script that edits several files, such as a session with multiple
   windows.

D  Delete the swap file.  Use this when you are sure you no longer need it.
   For example, when it doesn't contain changes, or when the file itself is
   newer than the swap file.
      On Unix this choice is only offered when the process that created the
   swap file does not appear to be running.

As far as I can tell abort is for when you use vim to check through multiple files, like so:

vim file1.txt file2.txt

If the first one is locked and you call quit, it will go on to file2.txt, whereas abort will break out of the application entirely.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.