“退出”和“中止”有什么区别?


23

当我尝试从多个vim实例打开文件时,出现以下错误提示:

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

“退出”和“中止”有什么区别?

我的第一个猜测是,当我尝试打开多个文件而在其他位置仅编辑一个文件时,“退出”可能会跳过一个文件,而“中止”可能会退出程序,但这显然是不正确的-两者都放弃了整个尝试在编辑并返回到终端。


2
:help swap-exists-choices回答您的问题吗?
FDinoff 2015年

@FDinoff会有所帮助,但对于“中止”我还是不太清楚。“还会中止更多命令。这在加载编辑多个文件的脚本时非常有用”-“其他命令”是否应该来自vim脚本?vim脚本打开新缓冲区真的足够普遍了吗?
凯文

Answers:


20

尝试以下操作:vim file1在终端中运行,然后vim -p file1 file2在其他终端中运行。第二条命令将提示您如上。如果回答Quit,您仍然可以进行编辑file2。如果回答Abort,则退出Vim,从而“中止所有其他命令”。


因此,在选项卡或拆分窗口(-p/ -o/ -O)中打开时只有区别吗?vim file1 file2编辑file1时,仅在退出和中止时完全使用退出;当编辑file2时,直到下一个提示时才出现提示,在这种情况下,退出和中止都将退回到file1。
凯文

1
你不明白 打开文件本质上是一系列命令。 vim file1 file2有两件事:设置参数(您可以使用进行访问的东西argv()),并将第一个文件加载到缓冲区中。实际上,仅在运行:n(或类似操作)时加载第二个文件。当Vim提示您已经设置了参数时,因此如果您Quit此时没有多余的命令可以运行。同样,其他事物也算作命令,fi autocmd和用设置的命令vim -c。您应该考虑所有这些命令,而不是受影响的文件。
lcd047

4

@FDinoff建议检查vim帮助。如果有人想更轻松地查看这些内容:

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.

据我所知,abort是您使用vim检查多个文件时的原因,例如:

vim file1.txt file2.txt

如果第一个被锁定并且您调用quit,它将进入file2.txt,而中止将完全退出应用程序。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.