Thursday, December 22, 2011

Re: What abbreviates filenames in tab labels?

On Thu, Dec 22, 2011 at 02:47, Rich Healey <healey.rich@gmail.com> wrote:
> :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.

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

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

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment