tags:

views:

1404

answers:

7

I open many files to Vim by

vim a/*.php

This opens 23 files.

I made my edit and run the following twice

:q

It closes all my buffers.

How can you close only one buffer in Vim?

A: 

You can use the :n command to move to the next file. :prev goes to the previous file.

Greg Hewgill
+1  A: 

How about

vim -O a a

That way you can edit a single file on your left and navigate the whole dir on your right... Just a thought, not the solution...

Santi
+4  A: 

Check your buffer id using :buffers

you will see list of buffers there like

1  a.php
2  b.php
3  c.php

if you want to remove b.php from buffer

:2bw

if you want to remove/close all from buffers

:1,3bw
nightingale2k1
+1  A: 

:ls = list buffers
:bd#n = close buffer where #n is the buffer number (use ls to get it)

example: delete buffer 2
:bd2

Shaun
+9  A: 

If this isn't made obvious by the the previous answers:

:bd will close the current buffer. If you don't want to grab the buffer list.

Cannonade
Before finding :bd it never made any sense to me that people had no problems doing a :ls -> scan for doc number -> unload buffer by number. Do people actually find this effective?
Svend
A: 

A word of caution: "w does not stand for write but for wipeout!"

More from manuals:

:bw

Like |:bdelete|, but really delete the buffer.

:bd

Unload buffer [N] (default: current buffer) and delete it from the buffer list. If the buffer was changed, this fails, unless when [!] is specified, in which case changes are lost. The file remains unaffected.

HH
+2  A: 

Maybe switch to using tabs?

vim -p a/*.php opens the same files in tabs

gt and gT switch tabs back and forth

:q closes only the current tab

:qa closes everything and exits

:tabo closes everything but the current tab

Leonid Shevtsov