I have a tabline function that I stole/modified from somewhere, but I would like the filename to have an asterisk before it if it has been modified since the last time it was written to disk (ie if :up would perform an action).
For example this is my tabline when I open vim -p file*.txt
file1.txt file2.txt file3.txt
Then after I change file1.txt and don’t save it:
*file1.txt file2.txt file3.txt
My tabline function:
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 .= ' %*'
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()
endif
I was just looking for the same and found that
%mand%Mis not well suited, as it tells you whether the currently open buffer is modified. So you cannot see if other buffers are modified (especially for tabs, this is important).The solution is the function
getbufvar. Roughly from the help:instead of
should do the trick. This can be used nicely to show all buffers open in one tab (in case of multiple splits).