Switch to last active buffer before opening tab
When switching to a new tab with t the tabline says NERD_tree_1.
How would I configure nerdtree to switch to the last active buffer before opening the new tab, so the message on the tab is more meaningful?
Seems like there's no config value or option for that.
Maybe with some autocmd for TabLeave or TabEnter?
I use the following code in my .vimrc
function MoveCursor()
let tab = tabpagenr()
let buflist = tabpagebuflist(tab)
for b in buflist
let buftype = getbufvar(b, "&filetype")
if buftype != 'nerdtree'
let bufnr = b
break
elseif b == buflist[-1]
let bufnr = b
endif
endfor
let nr = bufwinnr(bufnr)
exe nr . "wincmd w"
endfunction
Note though it doesn't switch to the last active buffer but to the first buffer in the tab that is not nerdtree.
If you don't mind nerdtree closing you can use the NERDTreeQuitOnOpen open to achieve the desired effect in the tabbar.
Thanks @AvSaba ! Switching to a buffer that is not nerdtree works for me! Based on your code I wrote my own function that does basically the same as yours, just with more descriptive variables, because I love those:) (and stepping over "help" buffers as well)
function NERDTreeStatusLineTabSwitch()
let tab_nr = tabpagenr()
let buffer_list = tabpagebuflist(tab_nr)
" default to 2
let meaningful_window_nr = 2
for buffer_nr in buffer_list
let buffer_type = getbufvar(buffer_nr, "&filetype")
if buffer_type != "nerdtree" && buffer_type != "help"
let meaningful_window_nr = bufwinnr(buffer_nr)
break
endif
endfor
exe meaningful_window_nr .. "wincmd w"
endfunction
autocmd TabLeave * call NERDTreeStatusLineTabSwitch()