Quit vim, when a buffer has unsaved changes and is

2019-04-06 11:15发布

I created a blank "scratch buffer" (i.e. not associated with a specific file) in vim, by using :vnew. Then I played around with some text, now I simply want to exit the editor - not keeping the contents of this "scratch buffer".

When I type the command:

:q!

Vim gives me:

[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

How can I quit vim from this state?

标签: vim editor
2条回答
Viruses.
2楼-- · 2019-04-06 11:47

At best you could call it a "transient" buffer (in memory but not associated with a specific file) but what you created with :vnew is not a "scratch" buffer.

In Vim, a "scratch" buffer is a normal buffer in which you set a bunch of local options. It can be done with a command like this:

:vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
查看更多
干净又极端
3楼-- · 2019-04-06 11:57

This happens when you have a modified hidden buffer. Use :qa! to exit anyway.

From :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.

In case someone wants to reproduce it:

  • Start vim and modify the unnamed buffer
  • Edit another file (you might need to :set hidden), ie :e README
  • Try to exit with :q!
查看更多
登录 后发表回答