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
> 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
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