Setting filenames in Tab
Can someone tell me how to display filename in the tabs when I open several files using Vim? Having a name on the tab would开发者_运维百科 make changing to different files much easier.
I think your question was "how do you display only the filename on your tab label". If that was the question, my answer is:
In a gui vim, you would use:
:set guitablabel=%t
However if's in vim, it gets a little more complicate. You have to overwrite the whole line, using :tabline. I modified the example provided in the :help setting-tabline, to add the behaviour you wanted. You would need to add the following code to your vimrc:
set tabline=%!MyTabLine()
function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'
endif
return s
endfunction
function MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let label = bufname(buflist[winnr - 1])
return fnamemodify(label, ":t")
endfunction
I hope this helps!
精彩评论