What abbreviates filenames in tab labels?

82 views
Skip to first unread message

Rich Healey

unread,
Dec 21, 2011, 8:47:35 PM12/21/11
to vim...@googlegroups.com
:he tablabel and :he setting-guitablabel both seem to suggest that set guitablabel=%N should put just the current buffer name in the tab title.

The test script I'm using is

mkdir -p /tmp/path/to/files
touch /tmp/path/to/files/file_{a,b,c}
vim -p /tmp/path/to/files/*

Which puts /t/p/t/f/file_a  /t/p/t/f/file_b  /t/p/t/f/file_c in the tab bar.

I want to implement something similar for fugitive, so I'm looking for the behaviour that controls this to implement it similarly.

Specifically, I'm looking for what controls folding all the directory elements in the path down to their first letters.

I'm sure I'm missing something obvious. Thanks.

Guido Van Hoecke

unread,
Dec 22, 2011, 4:11:17 AM12/22/11
to vim...@googlegroups.com

" use only filename and modified indicator as tablabel
set guitablabel=%{ShortGuiTabLabel()}

" ShortGuiTabLabel()
function! ShortGuiTabLabel()
" as mentionned by aidan.h...@googlemail.com
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

" Add short file name
let bufId = bufnrlist[tabpagewinnr(v:lnum) - 1]
let fn = bufname(bufId)
let lastSlash = strridx(fn, '\')
"added next 3 lines to cope with unix pathnames
if lastSlash < 0
let lastSlash = strridx(fn, '/')
endif
return label . strpart(fn, lastSlash+1, strlen(fn))
endfunction

Guido

--
Son, someday a man is going to walk up to you with a deck of cards on which
the seal is not yet broken. And he is going to offer to bet you that he can
make the Ace of Spades jump out of the deck and squirt cider in your ears.
But son, do not bet this man, for you will end up with an ear full of cider.
-- Sky Masterson's Father

http://vanhoecke.org ... and go2 places!

lith

unread,
Dec 22, 2011, 4:29:22 AM12/22/11
to vim...@googlegroups.com
Am Donnerstag, 22. Dezember 2011 02:47:35 UTC+1 schrieb Rich Healey:
Which puts /t/p/t/f/file_a  /t/p/t/f/file_b  /t/p/t/f/file_c in the tab bar.

I want to implement something similar for fugitive, so I'm looking for the behaviour that controls this to implement it similarly.

Are you looking for pathshorten()?

Regards,
Tom

Rich Healey

unread,
Dec 22, 2011, 7:45:01 AM12/22/11
to vim...@googlegroups.com
Thanks Guido,

I read this in the help for setting-guitablabel, but curiously this doesn't actually produce the default behaviour. As lith points out, I was indeed looking for pathshorten.
Reply all
Reply to author
Forward
0 new messages