Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Veritical split opening of already opened file doesn't work. #339

Closed
a-d-v-e-n-t-u-r-o-u-s opened this issue Aug 15, 2018 · 8 comments
Closed

Comments

@a-d-v-e-n-t-u-r-o-u-s
Copy link

Hello,
here is the scenario with which I got problem, maybe someone can help me with that:

  • open file hello.c in one tab
  • open file foo.c in another tab
  • use CommandT and search for hello.c and try to open it in vertical split to foo.c
  • view is switched to the first tab, where hello.c was already opened

Generally I'm using default settings of CommandT and current master from the SHA-1 sum:
7147ba9

@wincent
Copy link
Owner

wincent commented Aug 18, 2018

The code responsible for this behavior is in:

function! commandt#GotoOrOpen(command_and_args) abort
let l:command_and_args = split(a:command_and_args, '\v^\w+ \zs')
let l:command = l:command_and_args[0]
let l:file = l:command_and_args[1]
" `bufwinnr()` doesn't see windows in other tabs, meaning we open them again
" instead of switching to the other tab; but `bufname()` sees hidden
" buffers, and if we try to open one of those, we get an unwanted split.
if s:BufVisible(l:file)
execute 'sbuffer ' . l:file
else
execute l:command . l:file
endif
endfunction

It's basically trying to prioritize switching to a pre-existing view of buffer rather than opening a new one. I can see, though, why you might want to deprioritize things when the operation was explicitly "open this result in a vertical split" (and similarly for horizontal splits and probably tabs too). There are a lot of subtle nuances though (see wincent/wincent@8a95c3d for example), so may want to think about this carefully before making a change.

@artnez
Copy link
Contributor

artnez commented Aug 20, 2018

I had to revert back to an older version of Command-T. The new behavior messed up my workflow after years of muscle memory. I'm often hacking on multiple sections of the same file in a vertical split. Simply choosing an already open file will jump that file instead of opening it (in all cases).

If there was an option to disable GotoOrOpen I'd be happy to flip it on.

@a-d-v-e-n-t-u-r-o-u-s
Copy link
Author

By me is the use case similar as by artnez, I'm often using vertical splits on the same files. So generally in order to have this functionality we must change code snippet, which you have shown us.

@kentaroi
Copy link

Thank you very much for creating and maintaining this great plugin, @wincent .
However, I cannot accept this new behaviour.

I understand what I am doing. When I am opening a file with Command-T in a split, I do NOT want to move to another split, but want to open the file in that split.
If I want to move to another split, I move to that split without Command-T.

@wincent
Copy link
Owner

wincent commented Aug 30, 2018

Not really "new" behavior (the commit I linked to above is from four years ago, and merely brought things closer to the intended behavior). I'm happy to add some option for this, carefully (like I said above, there are many subtleties and nuances to take into account), and in the meantime you can revert back to an older version or hack the code yourself. Technically you should be able to have it without any code changes by resourceful manipulation of the g:CommandTAcceptSelectionSplitCommand (etc) settings, which can be used to completely bypass the CommandTOpen command (which is the one calling commandt#GotoOrOpen).

@kentaroi
Copy link

kentaroi commented Aug 30, 2018

Thank you very much for the quick reply and kind comments and suggestions, @wincent .
I'm sorry I misunderstood.
I just reverted back to version 4.0, and will look into g:CommandTAcceptSelectionSplitCommand etc.
I'm sorry to have bothered you by my complaint without looking into the settings.
Thank you again very much.

@wincent
Copy link
Owner

wincent commented Sep 19, 2018

So I just cut v5.0.3 from the next branch, and merged next into master too. I had forgotten, but a while back #315 changed the behavior here. I am not sure if that changes any of the points made here so far.

@a-d-v-e-n-t-u-r-o-u-s
Copy link
Author

I've temporary hacked my .vimrc file in following commit:

a-d-v-e-n-t-u-r-o-u-s/.dotfiles@18e9bda

I'm going to test it for a few days to see if this is working for me. @wincent thank you very much for hints.

@wincent wincent closed this as completed Mar 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants