Tony Mechelynck wrote:
Thanks!
[..]
> I'm not using that plugin, but I'm using a text-style tabline in both
> Console Vim and gvim.
I really needed the tab number, because I function mostly with a single
vim session that opens when I start X, and by the time I get to garbage
collection time, it can easily have some ten tabs open or more.. So I
had to count the tabs so as to be able to issue {count}gt's or else
issue a ":tabs" :-(
Since the author of the plugin would not stand up and be counted, I
actually proceeded to write my own last night :-)
> One example of how to set it can be found under ":help setting-tabline".
> What I use is slightly different, as follows (uncomment the maps at the
> bottom if you like them):
[..]
I tried it and it's quite similar to the one I wrote, although yours is
structured differently - and uses programming syntax I didn't even know
existed in the vim scripting language such as "a ? b : c" as a shorthand
for "if-then-else".
I blindly followed the :h setting-tabline example, basically testing
every statement from the command line and with the online help in front
of me till I could get it to do what I wanted. :-(
Interestingly, both our versions have similar (minor) bugs:
1. In your version, there should be a space between the last tab and
this mysterious "X" to the far right of the tab line. Otherwise the X
looks like it's part of the file name. I have a similar problem that I
had failed to notice where I have three spaces instead of one - thus
wasting space.
2. When opening more tabs than the width of the display can accommodate,
if you issue a "1"+"gt" you do move back the focus to tab #1, but the
beginning of the tab line is not displayed, which means that you may be
displaying part of tab #4 etc. and you are not able to see which tab you
are on, since the tab that should be highlighted is not visible. All you
see is a "<" in column one that indicates that there are more tabs to
the left but I haven't found the way to display them. Maybe something to
do with that right-justified final "X" - I'm curious what that "X" is
for.. I don't use a mouse, so maybe that's why it does nothing that I
can see. Maybe the "<" is clickable?
On the other hand, we both fixed another minor bug with vim's default
tab line, where the space immediately following the file name is
highlighted, which doesn't look right.
I'm still debating the usefulness of having the &modified flag
materialize in my version. Kinda of clutters the display and I'm not
really sure I need that, so I may remove it - or possibly remove the
number of windows in a tab - made the coding more fun but I don't think
I really care if a tab has three windows open rather than four.
I'm curious as to why the tab line was implemented this way rather than
something like the status line. I'm not complaining, mind you, writing a
simple function was definitely a fun and useful experience - vim is an
editor for programmers, not a word processor, right ;-) - but I'm not
sure why it was not done the same way for the terminal as for the gui -
cf. :h set guitablabel..?
What would be possible then is that since users normally display the
same data in all their tabs, provided they had been implemented, you
could simply refer to a list of items similar to the ones defined in ":h
'statusline'".
To clarify, the help file could look a bit like:
'tablabel'
...
item meaning
N tab number
n number of windows in tab
F full name of file in current window
f base name of file in current window
m tab has unsaved buffers - cf. &modified
etc.
Anyway, attaching what I came up with, if you care to take a peek..
Hopefully it's I'm not violating the list's policy.
It's fenc=utf8 & tw=80 so I'm not sure I could paste it in this message.
It has lots of useless comments that I had to put in there for my own
sake, just to keep track of what I was doing. :-)
Oh, one other thing.. I often toggle between two tabs say, that may not
be adjacent.. Does vim keep track of the previous tab you were on so
that I could switch back and forth between tab-x and tab-y..?
I didn't see anything in the manual.
Thanks,
Gen-Paul.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
"===============================================================================
" Custom tab line
"===============================================================================
function! MyTabLabel(n)
let label = ''
let label .= '['
let label .= a:n " set tab page number
let buflist = tabpagebuflist(a:n)
for bufnr in buflist
if getbufvar(bufnr, '&modified') " unsaved modified buffer?
let label .= '*'
break
endif
endfor
let wincount = tabpagewinnr(a:n, '$') " number of windows in tab
if wincount > '1'
let label .= ', ' . wincount " report how many windows
endif
let label .= '] ' " close bracket
let winnr = tabpagewinnr(a:n) " focused window number
let fullname = bufname(buflist[winnr - 1]) " absolute file name
let filename = fnamemodify(fullname, ':t') " basename
if filename == '' " empty buffers have No Name
let filename = '[No Name]'
endif
let label .= filename " add filename to label
return label
endfunction
function! MyTabLine()
let s = ''
for i in range(tabpagenr('$')) " for each open tab..
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#' " make active tab stand out
else
let s .= '%#TabLine#'
endif
let s .= '%{MyTabLabel(' . (i + 1) . ')}' " add tab label
let s .= '%#TabLine#' " reset highlight
if i + 1 != tabpagenr('$')
let s .= ' â ' " fancy tab separator
else
let s .= ' ' " except for the last tab
endif
endfor
let s .= '%#TabLineFill#%T' " :help statusline
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999XX' " right align the final 'X'
endif
return s
endfunction
:set tabline=%!MyTabLine()