I work in Vim with many open buffers in different windows on different tabs. I know that it is just easy to load one of the existing buffers into the current window. However, some of my large file buffers use folding expressions that cause a delay of several seconds when loading them into a new window. On the other hand, if they are already open in a window on a bookmark, I just need to go to this bookmark and this window.
I do not see any team for this. Or is there?
To find the window with the 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 is loaded into the correct buffer.
- move the cursor to the found window OR open the buffer in the window in a new tab, if not found
Has anyone already written this? Or did I miss an easier way to get what I want?
UPDATE: the โswitchbufโ answers were exactly what I was looking for, but I can still use the user-defined function because (1) I did not understand the behavior of the โnewtabโ option, since the windows were still split, and (2) my function supports search for uploaded 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
source share