0

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?

5
  • 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. – Dincio Apr 5 at 21:33
  • 1
    Ah, I see. The title contains the somewhat ambiguous "switch to it" so that's why I thought it. – B Layer Apr 5 at 21:41
  • 1
    Yes you're right... I changed it to make it more clear – Dincio Apr 5 at 21:43
  • 2
    In any case, welcome to Vi&Vim SE. :) – B Layer Apr 5 at 21:44
  • Thankyou that's very nice – Dincio Apr 5 at 21:51
2

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.

1
  • This is exactly what I needed, thankyou. – Dincio Apr 6 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.