tabline showing only the basename

View: New views
5 Messages — Rating Filter:   Alert me  

tabline showing only the basename

by Nicolas Aggelidis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


hi to all the list,

is there any way to make the tabline of gvim display only the basename
of the file and not its full name.

i.e /large/path/to/a/file.c to be displayed like file.c

because when you open a lot of tabs that are from different
directories the tabline size is messed up...

thanks in advance,
nicolas

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Re: tabline showing only the basename

by Dennis Benzinger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Nicolas!

Am 03.12.2008 15:10, Nicolas Aggelidis schrieb:
> hi to all the list,
>
> is there any way to make the tabline of gvim display only the basename
> of the file and not its full name.
> [...]

You want to set the guitablabel option. See :help guitablabel and :help
statusline for the fields you can use in the guitablabel option. You
probably want the %t field.


HTH,
Dennis Benzinger

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Re: tabline showing only the basename

by Ben Fritz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




On Dec 3, 8:25 am, Dennis Benzinger <Dennis.Benzin...@...> wrote:

> Hi Nicolas!
>
> Am 03.12.2008 15:10, Nicolas Aggelidis schrieb:
>
> > hi to all the list,
>
> > is there any way to make the tabline of gvim display only the basename
> > of the file and not its full name.
>
> You want to set the guitablabel option. See :help guitablabel and :help
> statusline for the fields you can use in the guitablabel option. You
> probably want the %t field.
>

Assuming that you're using the GUI version of Vim, of course.

Here's my setup, which I am quite fond of. It only shows the base name
like you want, and it additionally shows the tab number for easy
jumping between tabs with [count]gt. I additionally set up the
guitabtooltip option to allow me to see the full path. I'm fairly
certain that the google group will strip out all the indentation, so
you'll probably want to reindent the entire thing if you end up using
it:

set showtabline=2

" 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()}

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Re: tabline showing only the basename

by Tony Mechelynck-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 03/12/08 15:25, Dennis Benzinger wrote:

> Hi Nicolas!
>
> Am 03.12.2008 15:10, Nicolas Aggelidis schrieb:
>> hi to all the list,
>>
>> is there any way to make the tabline of gvim display only the basename
>> of the file and not its full name.
>> [...]
>
> You want to set the guitablabel option. See :help guitablabel and :help
> statusline for the fields you can use in the guitablabel option. You
> probably want the %t field.
>
>
> HTH,
> Dennis Benzinger

It's also possible in Console Vim (which uses 'tabline', not
'guitablabel') and when using a text-style tabline in the GUI (when
'guioptions' doesn't include the e flag). Here's how I do it:

if exists("+guioptions")
     set go-=a go-=e go+=t
endif
if exists("+showtabline")
     function MyTabLine()
         let s = ''
         let t = tabpagenr()
         let i = 1
         while i <= tabpagenr('$')
             let buflist = tabpagebuflist(i)
             let winnr = tabpagewinnr(i)
             let s .= '%' . i . 'T'
             let s .= (i == t ? '%1*' : '%2*')
             let s .= ' '
             let s .= i . ':'
             let s .= winnr . '/' . tabpagewinnr(i,'$')
             let s .= ' %*'
             let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
             let file = bufname(buflist[winnr - 1])
             let file = fnamemodify(file, ':p:t')
             if file == ''
                 let file = '[No Name]'
             endif
             let s .= file
             let i = i + 1
         endwhile
         let s .= '%T%#TabLineFill#%='
         let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
         return s
     endfunction
     set stal=2
     set tabline=%!MyTabLine()
     map    <F10>    :tabnext<CR>
     map!   <F10>    <C-O>:tabnext<CR>
     map    <S-F10>  :tabprev<CR>
     map!   <S-F10>  <C-O>:tabprev<CR>
endif


The User1 and User2 highlight groups, used by the above, are defined in
my "almost-default" colorscheme.


Best regards,
Tony.
--
It is only people of small moral stature who have to stand on their
dignity.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Re: tabline showing only the basename

by Nicolas Aggelidis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thank you guys, problem solved!

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---