If I have changed a bunch of files but without saving and maybe I have another pile of noname buffers which are changed and without a file name.

I want vim to prompt confirmation for each one of the above files. if it's a changed file without saving then ask me whether to save it. if it's a noname buffer asking me whether to save it, if yes then provide a file name.

It's just like in some other modeless editor, when you edit a lot of files and click the close button to close the editor, it'll prompt confirmations.

  • 3
    Well, technically, if you just do :q, Vim does warn about unsaved buffers.
    – muru
    Dec 18 '15 at 1:51
  • 1
    Well, what have you done to gVim, that it doesn't do it for you? It always asks me about unsaved buffers when pressing the 'X' Dec 18 '15 at 6:31
  • The command set confirm might be close to what you're asking for
    – Steve
    Dec 18 '15 at 10:25

The option confirm does what you describe for modified files.


set confirm

in my vimrc, it gives the following prompt when I :quit a modified NoName buffer:

Save changes to "Untitled"?
[Y]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel:

For me, if it's an unnamed buffer and you answer (Y)es to the prompt, it opens it. You could then :write filename, and :qall again (seems like any buffers you've already said (N)o to the prompt are cleared).

  • there's a problem, when I have multiple noname buffer, I can't figure out which noname buffer it's asking me to confirm, it always prompt the same message: save changes to "untitled"? [Y]es, [N]o ...
    – Aaron Shen
    Jan 3 '16 at 4:00
  • So you would like a preview of the file you are being asked about? I don't know how to do that.
    – Steve
    Jan 3 '16 at 11:06
  • As an idea, you could write a script to give the behaviour you're after. Maybe something that starts off by closing all non-modified buffers, perhaps something with if (&modified == 0)...
    – Steve
    Jan 3 '16 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.