tags:

views:

76

answers:

3

let's say currently there are two buffers in my vim session, and I want to close the current buffer which is under edit in order to switch the other buffer and edit it . using

:q 

will quit the whole vim rather than a buffer . so my question is are there any commands can close the current buffer under editing and automatically switch to the next buffer in the buffer list .

+6  A: 

Just doing a

:bd

should do it.

Edit: You can delete specific buffers as well using this command.

Get a list of your current buffers by entering:

:ls

This will give you something like:

1 #    "ap22_linux_build.sh.log"      line 87
2      "httpd-2.2.14-2010011600-linux32-g.build_log" line 4207
3 %a   "~/.bashrc"                    line 1

Take the relevant number and enter it before the bd command, so entering

: 2 bd

will delete the second buffer.

Rob Wells
+2  A: 

:bd (buffer delete) or :n (next)

The latter offers the advantage of being able to go back to the first file with :p (previous)

philippe
A: 

Theres also :bw which wipes the buffer as well. Eg. :bd will remove the buffer but you can get back to it if you hit ctrl-6.

I also really like bufexplorers 'd' key mapping in the buffer viewer, if your like me and get loads of buffers open its a quick way to go through and remove ones you dont need any more. http://www.vim.org/scripts/script.php?script_id=42

michael