Haiyuan Zhang
Haiyuan Zhang

Reputation: 42762

how to quit a buf in vim

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 .

Upvotes: 9

Views: 5421

Answers (3)

michael
michael

Reputation: 11847

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

Upvotes: 2

Rob Wells
Rob Wells

Reputation: 37103

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.

Upvotes: 17

philant
philant

Reputation: 35806

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

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

Upvotes: 4

Related Questions