Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of text files in a directory and I know I'll need to edit each one indiviudaly.

I start at the commend line with

vim *.txt

which opens the files as seperate buffers in vim and leaves me looking with at the first one. I edit it - then I use ':w' to save it and ':bd' to close the buffer and move on to the next one.

This ':w:bd' to save and close the buffer feels long to me, and I suspect there's a more vim ninja way of doing it - what's the recommend way to save and close the buffer you are working on in one felt swoop?

share|improve this question
    
My recomended way would be to just move to the :next buffer and write/close everything once your task is finished with :wqa. This supposes that you have :set hidden in your ~/.vimrc. –  romainl Jan 26 '13 at 13:14

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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