Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close a single buffer (out of many) in Vim?

Tags:

vim

buffer

I open several files in Vim by, for example, running

vim a/*.php 

which opens 23 files.

I then make my edit and run the following twice

:q 

which closes all my buffers.

How can you close only one buffer in Vim?

like image 409
Léo Léopold Hertz 준영 Avatar asked Aug 13 '09 01:08

Léo Léopold Hertz 준영


People also ask

How do I close one file in Vim?

You can also save your edits with ex commands. Type :w to save (write) your file but not quit vi; type :q to quit if you haven't made any edits; and type :wq to both save your edits and quit.

How do I close all buffers in Vim?

I use a variant of your solution: :%bd<CR><C-O>:bd#<CR> This will delete all buffers, then use <C-O> to get restore the position in the current file, then :bd# to remove the unamed buffer. This closes all buffers and leaves you in the same location in the file.

How do I delete a buffer?

Permanently deleting your Buffer accountClick on your profile avatar at the top right of your dashboard and then click Account from the drop down menu. Click Delete My Buffer Account towards the bottom of the page. Enter your password and click Confirm.

How do I switch between open buffers in Vim?

Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.


2 Answers

A word of caution: “the w in bw does not stand for write but for wipeout!”

More from manuals:

: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.

If you know what you’re doing, you can also use :bw

:bw

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

like image 52
hhh Avatar answered Sep 26 '22 23:09

hhh


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.

like image 29
RedBlueThing Avatar answered Sep 22 '22 23:09

RedBlueThing