Controlling Tab Names in Vim
vim
Solution
The following function returns the name of the buffer loaded in the top-left window:
function! GuiTabLabel()
return bufname(winbufnr(1))
endfunction
Since you've mentioned MacVim, you can use `guitablabel`, setting it to the function that we've defined:
set guitablabel=%{GuiTabLabel()}
A problem with the function above is that - depending on the working directory - it will set the tab name to the full path of the file in the top-left buffer, which can get pretty long.
Change the function to use only the filename, discarding the path:
function! GuiTabLabel()
return fnamemodify(bufname(winbufnr(1)), ":t")
endfunction
To persist this, define the function in your .vimrc, and after the function:
set guitablabel=%!GuiTabLabel()
But the simple set isn't working for me using MacVim: it looks like MacVim startup is overwriting my changes. Setting it in .gvimrc does work in MacVim. Between `:scriptnames` and `:verbose set guitablabel` it looks like just setting it in .vimrc should work, as it does in e.g. windows gvim.
See `:help setting-guitablabel` for more information and a more complicated function example; see `:help fname-modifiers` for more path-modifier options.
Problem
In MacVim, the names of tab appears to be set to the name of the buffer most recently opened in that tab. This makes for confusion when using splits. How can I fix the tabnames to the top-left window in a tab?