vifm / vifm.vim

Vim plugin that allows use of vifm as a file picker
325 stars 18 forks source link

Opening in split switches focus to wrong window #71

Closed mkdior closed 2 years ago

mkdior commented 2 years ago

To reproduce this: mkdir test && cd test touch a.txt b.txt echo 'aaaaa' > a.txt && echo 'bbbbb' > b.txt vim -p a.txt b.txt

Now if you switch your tab to b.txt and run :VsplitVifm and open a.txt- Vifm switches focus to the initial a.txt file instead of having b.txt in focus with a.txt in split.

Is this intended behaviour? When I work on projects I generally have a ton of tabs open, knowing whether or not I have a tab I want to open already open isn't something I can always track, thus if Vifm switches focus it kinda confuses me.

Thanks and much love

xaizek commented 2 years ago

This seems to be an effect of using :drop. If you remove Vifm from the test and after switching to the second tab do :split a.txt and :drop a.txt, same thing happens. This makes me think that it's a bug in Vim, focus shoudn't be switched to a different window if current one contains the same buffer.

:drop is used to switch to first file if you open several files at once, so it can be skipped in this use case, but Vim's behaviour still looks wrong.

mkdior commented 2 years ago

Thanks for moving this issue and thanks for the reply. I see, I guess it can't be helped without a fix from vim, correct? In that case, think it'd be good for this issue to be close, agree?

xaizek commented 2 years ago

I changed code to not call :drop for a single file (should be most of use cases), but the issue is still there if you open several files and the first one is already available in some other window. In this case Vim has to choose some window and it can be a wrong one, it can't really know which one is right so some more code changes might be needed here (remembering/iterating over windows).