当缓冲区有未保存的更改且未命名时退出 vim?
Quit vim, when a buffer has unsaved changes and is un-named?
我使用 :vnew
在 vim 中创建了一个空白 "scratch buffer"(即不与特定文件关联)。然后我玩弄了一些文本,现在我只想退出编辑器——不保留这个 "scratch buffer" 的内容。
当我键入命令时:
:q!
Vim 给我:
[No Name][+]
E37: No write since last change (add ! to override)
E162: No write since last change for buffer "[No Name]"
Press ENTER or type command to continue
如何退出 vim 这种状态?
当您有修改过的隐藏缓冲区时会发生这种情况。使用 :qa!
退出。
来自 :h :quit
:
:q[uit]! Quit without writing, also when currently visible
buffers have changes. Does not exit when this is the
last window and there is a changed hidden buffer.
In this case, the first changed hidden buffer becomes
the current buffer.
Use ":qall!" to exit always.
如果有人想复制它:
- 启动vim并修改未命名缓冲区
- 编辑另一个文件(您可能需要
:set hidden
),即:e README
- 尝试使用
:q!
退出
充其量您可以将其称为 "transient" 缓冲区(在内存中但不与特定文件相关联)但是您使用 :vnew
创建的是 而不是 一个"scratch"缓冲区。
在Vim中,"scratch"缓冲区是一个普通缓冲区,您可以在其中设置一堆本地选项。可以使用如下命令完成:
:vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
我使用 :vnew
在 vim 中创建了一个空白 "scratch buffer"(即不与特定文件关联)。然后我玩弄了一些文本,现在我只想退出编辑器——不保留这个 "scratch buffer" 的内容。
当我键入命令时:
:q!
Vim 给我:
[No Name][+]
E37: No write since last change (add ! to override)
E162: No write since last change for buffer "[No Name]"
Press ENTER or type command to continue
如何退出 vim 这种状态?
当您有修改过的隐藏缓冲区时会发生这种情况。使用 :qa!
退出。
来自 :h :quit
:
:q[uit]! Quit without writing, also when currently visible
buffers have changes. Does not exit when this is the
last window and there is a changed hidden buffer.
In this case, the first changed hidden buffer becomes
the current buffer.
Use ":qall!" to exit always.
如果有人想复制它:
- 启动vim并修改未命名缓冲区
- 编辑另一个文件(您可能需要
:set hidden
),即:e README
- 尝试使用
:q!
退出
充其量您可以将其称为 "transient" 缓冲区(在内存中但不与特定文件相关联)但是您使用 :vnew
创建的是 而不是 一个"scratch"缓冲区。
在Vim中,"scratch"缓冲区是一个普通缓冲区,您可以在其中设置一堆本地选项。可以使用如下命令完成:
:vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile