Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a tab in vim?

Tags:

vim

When I use :tabnew myfile in vim it opens a new tab.

When I quit the tab with :q and I move to another tab with :bn , the tab is still there.

Can someone explain why and how to really close it?

like image 661
orestiss Avatar asked Sep 22 '15 10:09

orestiss


People also ask

How do I close a window in Vim?

^Wc (or :close[!] ) closes the current window. If the hidden option is set and this is the last window referencing this file, Vim closes the window and the buffer is hidden. If this window is on a tab page and is the last window for that tab page, the window and the tab page are closed.

How do I toggle a tab in Vim?

To close a tab, use :tabc. To switch to the next tab, use :tabn, and to switch to the previous tab, use :tabp (short for tabnext and tabprevious respectively). You can also jump over tabs by using :tabn 2, which will move to the second next tab.


2 Answers

You can use :tabclose.

Read more with :help tabpage.


As for the buffer coming back with :bn, I believe this is normal for "hidden buffers", and :bn wraps around to the first buffer when you go past the last one.

See :help buffer-hidden

like image 111
ams Avatar answered Sep 19 '22 03:09

ams


You're mixing up tabs and buffers. A tab is simply a way of displaying buffers, closing it doesn't do anything to those.

If you want to delete a buffer from the buffer list, use :bd. From the help:

:[N]bd[elete][!]            *:bd* *:bdel* *:bdelete* *E516* :bd[elete][!] [N]         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.  Any windows for this buffer are         closed.  If buffer [N] is the current buffer, another buffer         will be displayed instead.  This is the most recent entry in         the jump list that points into a loaded buffer.         Actually, the buffer isn't completely deleted, it is removed         from the buffer list |unlisted-buffer| and option values,         variables and mappings/abbreviations for the buffer are         cleared. 
like image 24
Marth Avatar answered Sep 19 '22 03:09

Marth