Vim Tips Wiki
Register
(draft tip that makes working with multiple tabs much easier (maybe we need a "draft" template...))
 
(Insert TipProposed template + minor manual clean)
Line 1: Line 1:
  +
{{TipProposed
  +
|id=0
  +
|previous=0
  +
|next=0
  +
|created=November 30, 2009
  +
|complexity=basic
  +
|author=Fritzophrenic
  +
|version=7.0
  +
|subpage=/200911
  +
|category1=Tabs
  +
|category2=
  +
}}
 
{{dodgy|This tip is still in a draft version, not yet ready for general consumption. You can probably get some good use out of it, but ''caveat emptor''. Please feel free to improve this tip as much as you can!}}
 
{{dodgy|This tip is still in a draft version, not yet ready for general consumption. You can probably get some good use out of it, but ''caveat emptor''. Please feel free to improve this tip as much as you can!}}
   
Line 82: Line 94:
 
set guitabtooltip=%{GuiTabToolTip()}
 
set guitabtooltip=%{GuiTabToolTip()}
 
</pre>
 
</pre>
  +
[[Category:Tabs]]
 
  +
==Comments==

Revision as of 22:59, 1 December 2009

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created November 30, 2009 · complexity basic · author Fritzophrenic · version 7.0

It can be hard to quickly determine the tab number you want when jumping to a specific tab by giving a count to the gt command. This makes it easier by displaying the tab page number at the beginning of the tab page text. Note, only works in gui Vim. Need to tweak to use tablabel option for terminal Vim. Can probably lose the tooltip portion.

Drop the following in your vimrc:

set showtabline=2 " always show tabs in gvim, but not vim

" set up tab labels with tab number, buffer name, number of windows
function! GuiTabLabel()
  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 tab number
  let label .= tabpagenr().': '

  " Append the buffer name
  let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
  if name == ''
    " give a name to no-name documents
    if &buftype=='quickfix'
      let name = '[Quickfix List]'
    else
      let name = '[No Name]'
    endif
  else
    " get only the file name
    let name = fnamemodify(name,":t")
  endif
  let label .= name

  " Append the number of windows in the tab page
  let wincount = tabpagewinnr(v:lnum, '$')
  return label . '  [' . wincount . ']'
endfunction

" set up tab tooltips with every buffer name
function! GuiTabToolTip()
  let tip = ''
  let bufnrlist = tabpagebuflist(v:lnum)

  for bufnr in bufnrlist
    " separate buffer entries
    if tip!=''
      let tip .= ' | '
    endif

    " Add name of buffer
    let name=bufname(bufnr)
    if name == ''
      " give a name to no name documents
      if getbufvar(bufnr,'&buftype')=='quickfix'
        let name = '[Quickfix List]'
      else
        let name = '[No Name]'
      endif
    endif
    let tip.=name

    " add modified/modifiable flags
    if getbufvar(bufnr, "&modified")
      let tip .= ' [+]'
    endif
    if getbufvar(bufnr, "&modifiable")==0
      let tip .= ' [-]'
    endif
  endfor

  return tip
endfunction

set guitablabel=%{GuiTabLabel()}
set guitabtooltip=%{GuiTabToolTip()}

Comments