我的第一个猜测是,当我尝试打开多个文件而在其他位置仅编辑一个文件时,“退出”可能会跳过该文件,而“中止”则退出该程序,但这显然是不正确的-两者都只是放弃了整个编辑尝试,而是回到了终端。
#1 楼
尝试以下操作:在终端中运行vim file1
,然后在其他终端中运行vim -p file1 file2
。第二条命令将提示您如上。如果回答Quit
,仍然可以编辑file2
。如果回答Abort
,则退出Vim,从而“中止任何其他命令”。评论
因此,在选项卡或拆分窗口(-p / -o / -O)中打开仅存在区别吗?仅当使用vim file1时,在编辑file1时,file2会在quit和中止时完全退出;并且在编辑file2时,直到下一个提示时才出现提示,在这种情况下,退出和中止都将退回到file1。
–凯文
15年5月12日在17:46
你不明白打开文件本质上是一系列命令。 vim file1 file2有两件事:设置参数(您可以使用argv()访问的东西),并将第一个文件加载到缓冲区中。实际上只有在运行:n(或类似命令)时才加载第二个文件。当Vim提示您已设置参数时,因此如果您退出该命令,则不再有“更多”命令可以运行。另外,其他东西也算作命令。使用vim -c设置的autocmds和命令。您应该考虑所有这些命令,而不是受影响的文件。
–lcd047
15年5月12日在18:23
#2 楼
@FDinoff建议检查vim帮助。如果有人想更轻松地查看这些内容:据我所知,中断是指使用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.
如果第一个被锁定并且您调用quit,它将进入file2.txt,而中止将完全退出应用程序。
评论
:help swap-exists-choices回答您的问题吗?@FDinoff会有所帮助,但对于“中止”我还是不太清楚。 “还会中止更多命令。在加载编辑多个文件的脚本时,这很有用。”-“其他命令”是否应该来自vim脚本? vim脚本打开新缓冲区真的很常见吗?