代码之家  ›  专栏  ›  技术社区  ›  the_velour_fog

当缓冲区有未保存的更改且未命名时,退出vim?

  •  12
  • the_velour_fog  · 技术社区  · 9 年前

    我使用 :vnew 。然后我玩了一些文本,现在我只是想退出编辑器-而不是保留这个“暂存缓冲区”的内容。

    键入命令时:

    :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?

    2 回复  |  直到 6 年前
        1
  •  23
  •   Marth    9 年前

    当您修改了隐藏缓冲区时,就会发生这种情况。使用 :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!
        2
  •  6
  •   romainl    9 年前

    最好您可以将其称为“暂时”缓冲区(在内存中,但与特定文件无关),但您使用 :vnew “刮擦”缓冲区。

    在Vim中,“scratch”缓冲区是一个普通的缓冲区,您可以在其中设置一组本地选项。可以使用如下命令完成:

    :vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile