Ahu Lee
Ahu Lee

Reputation: 399

What is "a modified hidden buffer"? Can I disable this thing?

I'm using a portable version of gVim 8.0 and every time I want to start a new "file"\session (I have no idea how should I call it frankly) using :enew command or if I want simply to quit the program using :q (:quit) I got this error message:

E37: No write since last change (add ! to override).

Here I read that this happens when you have a modified hidden buffer. I don't know what that buffer is but I don't like this default behavior. Can I change it somehow so I wouldn't type the question mark every time I need to quit or start anew?

Thank you!

Upvotes: 2

Views: 932

Answers (1)

phd
phd

Reputation: 94716

Set options autowrite and autowriteall. They allow to write the contents of the file, if it has been modified, on each :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, :make, CTRL-] and CTRL-^; autowriteall also used for commands ":edit", ":enew", ":quit", ":qall", ":exit", ":xit", ":recover" and closing the Vim window.

:set autowrite
:set autowriteall

in the current session. Put "set autowrite" and "set autowriteall" in ~/.vimrc to make this automatic in the future sessions.

If you don't want to automatically write modified buffers but simply switch to another buffer

:set hidden

(again, both in command line and ~/.vimrc).

If autowrite doesn't work it probably means that the buffer doesn't have a name (isn't associated with a file) — in that case vim cannot write the buffer. set hidden helps here but not for :q. vim can automatically save files but cannot (and shouldn't) automatically discard changes. You have to discard them explicitly with :qa!. This is safety feature.

Upvotes: 5

Related Questions