I work in Vim with lots of open buffers in various windows on various tabs. I know it's simple to just load one of the existing buffers into my current window. However, some of my buffers for large files use folding expressions that cause delay of several seconds when loading them into new window. On the other hand, if they are already open in window on a tab page I just need to hop to that tab page and that window.
I gather there's no command to do this directly. Or is there?
To find window with desired buffer I could write a function that does this:
- for each tab
- for each window on each tab
- check each window to see if it has my desired buffer loaded
- move cursor to found window OR open buffer in window on new tab if not found
Has someone already written this? Or am I missing simpler way of getting what I want?
UPDATE: The 'switchbuf' answers were exactly what I was looking for, but I still may end up using a custom function because (1) I was not understanding the behavior of 'newtab' option, since windows were still being split, and (2) my function accommodates searches for unloaded files:
function! Sbuf(filename)
let myvar = ''
tabdo let myvar = bufwinnr(a:filename) > 0 ? tabpagenr()
\ . ' ' . bufwinnr(a:filename) : myvar
if myvar > ''
silent execute split(myvar)[0] . "tabn"
silent execute split(myvar)[1] . "wincmd w"
else
execute 'tab drop ' . a:filename
endif
endfunction