Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim automatically show left tab after closing tab

Tags:

vim

After closing a tab in vim, how do I make it so that the tab to the left is the one automatically shown?

The default when closing a tab seems to be showing the right tab, which is annoying because new tabs OPEN on the right of your current tab. So opening a new tab and closing it leaves you on a different tab.

like image 646
timidpueo Avatar asked Dec 29 '12 06:12

timidpueo


People also ask

How do I close a single tab in vim?

You can type Ctrl-W c to close the current window. If that window is the last window visible in a tab, the tab is also closed (if another tab page is currently open).

How do I rearrange tabs in vim?

You can use :tabmove followed by the tab number to move past. For example, :tabmove 3 will make the current tab move past the 3rd. :tabmove 0 moves to the beginning and :tabmove (without a number) moves to the end.

How do I close all sessions in vim?

Esc + :qa + Enter (Quit all open files) Esc + Shift ZZ (Save and exit) Esc + Shift ZQ (Exit without saving)


2 Answers

A patch has been proposed to add a 'tabcloseleft' option; it is on the todo list to be integrated into Vim (some time in the future, once Bram has time to work on it).

like image 130
Ingo Karkat Avatar answered Nov 24 '22 01:11

Ingo Karkat


There is one idea: though there is no TabClose event there is TabEnter event which could be used to achieve what you want: if on one of the events number of tabs is less then previously recorded number then obviously it was triggered due to closed tab:

let s:prevtabnum=tabpagenr('$')
augroup TabClosed
    autocmd! TabEnter * :if tabpagenr('$')<s:prevtabnum && tabpagenr()>1
                \       |   tabprevious
                \       |endif
                \       |let s:prevtabnum=tabpagenr('$')
augroup END
like image 32
ZyX Avatar answered Nov 23 '22 23:11

ZyX