Quantcast

setting vim tabline

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

setting vim tabline

Nicolas Aggelidis

hi to all the list! a fellow vimmer (from the list) has posted the
following tabline for gvim [i don't recall if it was exactly the
same]:

function! VimTabLabel()
 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[tabpagenr(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

this function ,works great for gvim, but when i try to use it with
vim, i get the following errors:

Error detected while processing function VimTabLabel:
line    5:
E714: List required
line   16:
E15: Invalid expression: 0
Press ENTER or type command to continue

is there any way to convert it for vim?

thanks in advance for any help,
nicolas

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: setting vim tabline

Erik Falor

On Tue, Mar 31, 2009 at 02:28:12PM +0300, Nicolas Aggelidis wrote:

> hi to all the list! a fellow vimmer (from the list) has posted the
> following tabline for gvim [i don't recall if it was exactly the
> same]:
>

[code snipped...]

>
> this function ,works great for gvim, but when i try to use it with
> vim, i get the following errors:
>
> Error detected while processing function VimTabLabel:
> line    5:
> E714: List required

On line 5 of the function, the variable v:lnum was referenced.
From :help v:lnum:
                        *v:lnum* *lnum-variable*
v:lnum      Line number for the 'foldexpr' |fold-expr| and 'indentexpr'
        expressions, tab page number for 'guitablabel' and
        'guitabtooltip'.  Only valid while one of these expressions is
        being evaluated.  Read-only when in the |sandbox|.

The problem was that guitablabel isn't called from within console Vim,
so v:lnum doesn't have a valid value for the purposes of
tabpagebuflist().

> is there any way to convert it for vim?

Not really.  There isn't an analog to the 'guitablabel' setting in
console Vim.  The closest thing is 'tabline', which operates rather
differently.  Instead of writing a function which makes one label at a
time, in console Vim you build the tabline in one shot.

Read up on it:
:help tabline

There's a nice example in the docs that you can tweak to your liking.

--
Erik Falor
Registered Linux User #445632 http://counter.li.org

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: setting vim tabline

Tony Mechelynck

On 31/03/09 17:26, Erik Falor wrote:
> On Tue, Mar 31, 2009 at 02:28:12PM +0300, Nicolas Aggelidis wrote:
[...]

> The problem was that guitablabel isn't called from within console Vim,
> so v:lnum doesn't have a valid value for the purposes of
> tabpagebuflist().
>
>> is there any way to convert it for vim?
>
> Not really.  There isn't an analog to the 'guitablabel' setting in
> console Vim.  The closest thing is 'tabline', which operates rather
> differently.  Instead of writing a function which makes one label at a
> time, in console Vim you build the tabline in one shot.
>
> Read up on it:
> :help tabline
>
> There's a nice example in the docs that you can tweak to your liking.
>

I'm using the following since that option appeared in Vim 7.00aa alpha,
and it has suited me quite well since then:

if exists("+guioptions")
     set go-=e
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

Notes:
- go-=e means this text-style tabline shall be used even in the GUI.
- The four commented-out mappings at the bottom can be included or not,
depending on personal preferences.


Best regards,
Tony.
--
Being stoned on marijuana isn't very different from being stoned on
gin.
                -- Ralph Nader

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

Loading...