2

I opened _gvimrc from Vim's HOME folder.
Made a small edit.
Escaped from edit mode.
Executed :w to save the change.
Then tried to close the file by executing :close but it says E444: Cannot close last window

If I go to the File menu and click the menuitem Close (which says :close next to it) then it closes fine.

Why does File>Close close the file happily but :close does not?


EDIT

This is my File menu:

enter image description here

4

1 回答 1

1

来自:he :close

CTRL-W c *CTRL-W_c* *:clo* *:close* :clo[se][!] Close current window. When the 'hidden' option is set, or when the buffer was changed and the [!] is used, the buffer becomes hidden (unless there is another window editing it). When there is only one window in the current tab page and there is another tab page, this closes the current tab page. |tab-page|. This command fails when: *E444* - There is only one window on the screen. - When 'hidden' is not set, [!] is not used, the buffer has changes, and there is no other window on this buffer. Changes to the buffer are not written and won't get lost, so this is a "safe" command.

基本上,菜单项close window是错误的,并且匹配:quit关闭当前窗口的实际内容,或者如果这是最后一个窗口,则匹配当前的 vim 会话:

*:q* *:quit* :q[uit] Quit the current window. Quit Vim if this is the last window. This fails when changes have been made and Vim refuses to |abandon| the current buffer, and when the last file in the argument list has not been edited. If there are other tab pages and quitting the last window in the current tab page the current tab page is closed |tab-page|. Triggers the |QuitPre| autocommand event.

而 IINW,实际上是:confirm quit. 因此,如果您在菜单选项:close旁边的选项是正确的close,那肯定是一个需要修补的错字。

编辑:

好的,刚刚在#vim IRC 频道上与一些人进行了讨论。在那里,我被告知了该:menu命令,您可以通过以下方式访问 file->close 命令:menu File.Close

To create a new menu item, use the ":menu" commands.  They are mostly like
the ":map" set of commands but the first argument is a menu item name, given
as a path of menus and submenus with a '.' between them, e.g.: >

:menu File.Save  :w<CR>
:inoremenu File.Save  <C-O>:w<CR>
:menu Edit.Big\ Changes.Delete\ All\ Spaces  :%s/[ ^I]//g<CR>

关闭操作绝对不是:close,而是菜单的内置WinClose( BuiltIn17), :he builtin-tools。它做的事情与:close.

但无论如何,除了那个错误/错字,如果你是 vim 的新手,你最好学会在没有菜单的情况下使用它。您需要的一切都在您的指尖之下。浏览vimtutor、玩vimgolf、阅读一些教程,并尝试每个月学习和使用一个新命令。你最终会变得更有效率,并且忘记你的鼠标......</p>

于 2013-05-05T14:32:23.420 回答