tags:

views:

1142

answers:

4

As I open new tabs in vi/vim(7.2), if the opened files are in different paths the tab title displays the complete path and hogs the screen real estate so the other tabs are not visible. This means I can't use my mouse to click to the tab I want but have to resort to : & keyboard commands to move between tabs.

Is there any way I can restrict the tab titles to a max 'size/length', so I only get to see say the last 12 characters of a file in a distant relative path ?

+1  A: 
:help setting-tabline

Seems to have the relevant information, but I'm not familiar enough with vim scripting to be able to help you get the exact effect you want. Hopefully someone else can pick up from this point.

Also see:

:help statusline

For some info about printing various information, that should be useful.

Chad Birch
A: 

In reply to my own question:

After reading Chad Birch above and googling for setting-tabline I found the TabLineSet plugin that does the trick, and some of script explanations here

molicule
Could you add some examples. The documentation is insufficient.
Casey
install the TabLineSert plugin and in your .vimrc file set the variables you want as follows: "let g:TabLineSet_max_tab_len = 20" for a full list of TabLineSet_ vars look at TabLineSet.vim
molicule
A: 

I found the following blog post was the most concise of all.

The link provides the following function which should be placed in your .gvimrc file.

function! GuiTabLabel()
    " add the tab number
    let label = '['.tabpagenr()

    " modified since the last save?
    let buflist = tabpagebuflist(v:lnum)
    for bufnr in buflist
     if getbufvar(bufnr, '&modified')
      let label .= '*'
      break
     endif
    endfor

    " count number of open windows in the tab
    let wincount = tabpagewinnr(v:lnum, '$')
    if wincount > 1
     let label .= ', '.wincount
    endif
    let label .= '] '

    " add the file name without path information
    let n = bufname(buflist[tabpagewinnr(v:lnum) - 1])
    let label .= fnamemodify(n, ':t')

    return label
endfunction

set guitablabel=%{GuiTabLabel()}
Casey
+1  A: 

You can do this pretty nicely for gvim with the setting 'guitablabel'.

Here's an excerpt from my .gvimrc, which modifies the default to only show up to 12 characters of the filename, but keeps the '+' for modified buffers. The tooltip is left unmodified, so you can get the full path from that or by pressing Ctrl-G in command mode.

if version >= 700
    "set showtabline to show when more than one tab
    set showtabline=1
    "set tab labels to show at most 12 characters
    set guitablabel=%-0.12t%M
endif

" don't show the toolbar in the GUI (only the menu)
set guioptions-=T

" don't show tear-off menus
set guioptions-=t
werkshy