Vim - save and close buffer in one command

When passing the files to Vim on the command-line, they are not only opened in buffers, but also populate the argument list. Therefore, you can use commands like :next and :first to navigate through them (and :argdo for batch processing, which can be a nifty trick). The command I recommend for your question is :wnext (short form :wn), which :writes the current buffer and then goes to the :next one.

You don't need to explicitly :bdelete a buffer, especially not when you're launching Vim from the command-line with a set of files and then quit it when you're done. (The only exceptions I can think of is unloading a huge file to save system memory, or re-using a single GVIM instance for many different edits.)

However, if you really want this, just define a custom command, e.g.

:command Wd write|bdelete

While I agree that you don't have to delete open buffers you aren't currently using, I like to delete them because I have vim-airline's tab line enabled, which shows all open buffers all the time at the top of the window. I have the following in my .vimrc:

nnoremap qq :w\|bd<cr>

qq saves and closes the current buffer, but also messes with the "record macro" functionality of vim (which I'm okay with).

Tags:

Vim

Buffer