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.

Aaron Shen
  • 2,519
  • 3
  • 24
  • 37

1 Answers1

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

Steve
  • 446
  • 4
  • 9
  • 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 03 '16 at 04: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 03 '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 03 '16 at 11:29