vmassuchetto
vmassuchetto

Reputation: 1569

Annoying vim tab line labels

That's not an indentation question.

Vim's behavior for window navigation really annoys me. Suppose there's this configuration of windows current opened, and the file wp-config-sample.php is the current one:

enter image description here

As all the other files are in a different directory, if I focus any of them doing a <ESC>gt, all of them get their content changed, and the tabs get resized as well:

enter image description here

That's a simple example, but the problem really arises when there's a lot of tabs opened and I can't just figure out where I am, because the focused tab changed its position significantly from the original one.

What I expect as a good behavior is the same system on Firefox, where the focused and unfocused tab never change their position, and the focused one only gets slightly emphasized.

Is there any way of making it stop?

Upvotes: 5

Views: 3854

Answers (4)

Martin
Martin

Reputation: 1001

For gVim I use

:set guitablabel=%N/\ %t\ %M

and thus have a tab label that shows:

  • tab number
  • filename
  • if modified a '+' next to the name

Upvotes: 0

cptstubing06
cptstubing06

Reputation: 322

Yep, the default tab labels make the tabs really annoying when you have autochdir on. Basically, they're showing you the full path (abbreviated) if your :pwd is something other than the file's location, and just the filename if your :pwd is the same as the file's. When you have autochdir on, your :pwd changes any time you load a buffer, including when you switch tabs. I happen to like autochdir, because :ls and any file operations are automatically relative to the active buffer's cwd. I always know that location, because I have the full path in my status line.

I have gui tabs set to show me a few different things... Tab number, modified indicator, if there's more than one window in the tab (show the count), and always show just the file name of the buffer (using the one in the active window if there is more than one window).

" GUI Tab label full path
function! GuiTabLabeler()
  let tabno = tabpagenr()
  let label = ''
  let bufnrlist = tabpagebuflist(v:lnum)

  " Add '+' if one of the buffers in the tab page is modified
  for bufnr in bufnrlist
    if getbufvar(bufnr, "&modified")
      let label = '[+]'
      break
    endif
  endfor

  " Append the number of windows in the tab page if more than one
  let wincount = tabpagewinnr(v:lnum, '$')
  if wincount > 1
    let label .= ' [' . wincount . ']'
  endif

  " Append the buffer name
  return tabno . " " . 
         \ fnamemodify(bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]), ":t")
         \ . label
endfunction

set guitablabel=%!GuiTabLabeler()

Tab numbers in the tabs are nice, particularly if you do something like map your alt-number keys to them:

" Tab navigation in with alt-#
noremap <A-1> :tabnext 1<CR>
noremap <A-2> :tabnext 2<CR>
noremap <A-3> :tabnext 3<CR>
noremap <A-4> :tabnext 4<CR>
noremap <A-5> :tabnext 5<CR>
noremap <A-6> :tabnext 6<CR>
noremap <A-7> :tabnext 7<CR>
noremap <A-8> :tabnext 8<CR>
noremap <A-9> :tabnext 9<CR>
noremap <A-0> :tabnext 0<CR>

This way, my gui tabs stay pretty narrow and clean. I prefer to have the filename with the full path in my status line (among other things):

" Statusline 
set laststatus=2
let &statusline='%F  %r%m  [%{&fileformat}]%y[%{strlen(&fenc)?&fenc:&enc}]'
           \ . '%= --%3p%% --   l:%3l, c:%3c (%03b 0x%02B)'

Upvotes: 1

vmassuchetto
vmassuchetto

Reputation: 1569

tappi, on #vim at Freenode, clarified that I have autochdir turned on. To quickly fix this:

:set noautochdir

And coot pointed me a nice vim's wiki link, with a nice snippet that works really well in .vimrc, to preserve the autochdir behavior and also keep a regular tab title when switching through windows.

Now my tabs are beautiful!

Upvotes: 3

bitmask
bitmask

Reputation: 34636

Yes, you can display only the filenames themselves in Vim. See :h tabline and :h filename-modifiers.

Upvotes: 1

Related Questions