A.J.Mechelynck wrote:
A.J.Mechelynck wrote:
Kim Schulz wrote:
hi is there an equivalent to bufexists() and bufnr() but for tabs in vim
7?
There is no need for an "equivalent". bufexists() and bufnr() will
show that a buffer exists, and give its number, even if it is not
currently loaded in a window; indeed even if it is "unlisted" i.e.,
listed by ":ls!" (with bang) but not by ":ls" (without bang). After
":bdelete" (but not after ":bwipeout") bufexists() is still TRUE for
the just "deleted" buffer.
bufloaded() will answer TRUE if a buffer is loaded in a window, but
also if it is loaded in memory but hidden (not loaded in any window).
To see if a buffer is loaded in a window, use
if bufwinnr('/path/to/filename.ext') != -1
To see if a buffer is loaded in a window in the n-th tab page:
function! BufferTabWindow(tab, bufid)
let bufno = bufnr(a:bufid)
let i = 1
while i <= tabpagewinnr(a:tab, '$')
if tabpagebuflist(a:tab, i-1) == bufno
return i
endif
i += 1
endwhile
endfunction
which (if I didn't goof) should return 0 if the buffer is not loaded
in the tab in question, and the window number (a non-zero number) if
it is. If the buffer in question is loaded in more than one window in
the concerned tab, the number of the first of those windows should be
returned.
Best regards,
Tony.
Oops; I did goof. "i += 1" sould of course be "let i += 1" just before
the "endwhile".
Best regards,
Tony.
... and tabpagebuflist(a:tab, i-1) should have been
tabpagebuflist(a:tab)[i-1]
Watch out: I just woke up. Maybe I left others errors still.
Best regards,
Tony.