7

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
  • 3
    Well, technically, if you just do :q, Vim does warn about unsaved buffers.
    – muru
    Commented Dec 18, 2015 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' Commented Dec 18, 2015 at 6:31
  • The command set confirm might be close to what you're asking for
    – Steve
    Commented Dec 18, 2015 at 10:25

1 Answer 1

12

The option confirm does what you describe for modified files.

With

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).

3
  • 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
    Commented Jan 3, 2016 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
    Commented Jan 3, 2016 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
    Commented Jan 3, 2016 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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