Let's say I have a way of identifying (through name or number) a buffer which is already open in a window somewhere. How can I focus on the window that hosts said buffer? Can this be generalizable so that I can find this window even if it lives in another tab?
-
No actually I can also do it by buffer number... I have access to the whole buffer python object. I think the linked answer only adresses switching buffer by substituing the found buffer in the current window. I'm interested in jumping to another window where the target buffer already resides.– DincioApr 5, 2021 at 21:33
-
1Ah, I see. The title contains the somewhat ambiguous "switch to it" so that's why I thought it.– B LayerApr 5, 2021 at 21:41
-
1Yes you're right... I changed it to make it more clear– DincioApr 5, 2021 at 21:43
-
2In any case, welcome to Vi&Vim SE. :)– B LayerApr 5, 2021 at 21:44
-
Thankyou that's very nice– DincioApr 5, 2021 at 21:51
1 Answer
You can use the functions win_findbuf
, bufnr
, and win_gotoid
as follows:
let wins = win_findbuf(bufnr('name'))
call win_gotoid(wins[0])
This goes to the "first" buffer that contains the window, and the list will be ordered by tab and window number. Also left as an exercise to handle the error case where no window contains your buffer.