Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to quit a buf in vim

Tags:

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 .

like image 647
Haiyuan Zhang Avatar asked Jan 18 '10 12:01

Haiyuan Zhang


People also ask

How do I close a buffer in Vim?

Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).

How do I close Emacs buffer?

C-x k to kill the current buffer. C-x 0 to close the current window. C-x 1 to close every other window.

How do you close a file in Vim?

To save a file in Vim and exit, press Esc > Shift + ZZ. To exit Vim without saving, press Esc > Shift + ZX.

How do I close all open files in Vim?

You can quit from all open files (buffers) by :qa or :qa! In vim. The exclamation mark means to force quit the edited unsaved file.


3 Answers

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.

like image 98
Rob Wells Avatar answered Nov 11 '22 10:11

Rob Wells


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

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

like image 32
philant Avatar answered Nov 11 '22 09:11

philant


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

like image 2
michael Avatar answered Nov 11 '22 11:11

michael