0

I have a tab with the following window structure within:

________________________________
a                               |
                                |
               x                |
________________________________|
b                               | 
                                |
                                |
________________________________|

x is the cursor position.

:ls lists two buffers open on this tab: Main.cpp and maininclude.h

Main.cpp is visible on a, and maininclude.h is visible on b. From a, if I issue command :find maininclude.h, this buffer is (re)opened in a, even though it is currently activie/visible in b. That is, I end up having two views in two different windows of the same file that I would like to avoid.

Is there a way to favor/privilege the window in which a current buffer is active/visible so that a :find for that file/buffer issued from any window in the tab automatically goes to that window and places the cursor there? If that buffer is not active/visible in any window, then indeed that buffer should be made active in the window from which :find was issued from.

An animated gif example of what I am facing is provided here, reproduced below:

enter image description here


Edit1: set switchbuf=useopen does not work.

See image gif here, reproduced below:

enter image description here

6
  • 1
    set switchbuf=useopen
    – Biggybi
    Commented Sep 19, 2021 at 6:16
  • @Biggybi see edit in OP. switchbuf does not work
    – Tryer
    Commented Sep 19, 2021 at 6:40
  • 1
    Then either find does not respect it or your config somehow disables it. I can't try rn. You should give a shot at sb or other commands.
    – Biggybi
    Commented Sep 19, 2021 at 7:24
  • 1
    @Biggybi I am indeed able tto confirm that :sb filename works with switchbuf=useopen as you mentioned -- moving to a previously existing window itself.
    – Tryer
    Commented Sep 19, 2021 at 7:30
  • The only commands that respect switchbuf are listed in the help for the option. OTOH, If that is an acceptable answer to your question Tryer, please add an answer (or ask Biggybi too).
    – D. Ben Knoble
    Commented Sep 22, 2021 at 20:06

1 Answer 1

2

As suggested in the comments, set switchbuf=useopen does not work with :find. What this means is that if you :find b with cursor in a, then b will be opened in a's window regardless of how switchbuf is set.

However, if from a, one issues :sb b, then indeed the focus shifts to b in the bottom window pane leaving a untouched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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