zefei / vim-wintabs

Modern buffer manager for Vim
MIT License
325 stars 25 forks source link

Suggestion for "vsplit or open existing" #12

Closed jordwalke closed 7 years ago

jordwalke commented 7 years ago

It's really common for modern editors to encourage each file to be open in one "window" or viewport. Vim stands at odds against this so much of the time. Thankfully WinTabs helps bring Vim closer to a modern editor. There is one area where it could stand to improve. It seems there should be a command for the following features:

jordwalke commented 7 years ago

In summary:

zefei commented 7 years ago

This sounds like a good feature to have next, thanks for the suggestion! I'll probably make it in two or three weeks. Although the command is quite easy to code, hooking it into all the cases that you can open a file (, <C-[>, gf, quickfix, CtrlP, Nerdtree, etc) is quite challenging.

jordwalke commented 7 years ago

I agree that integration is the most challenging part, however, I have vim config called VimBox Where I've done all of this setup for CtrlP and NerdTree (I don't know how to do it for gf, but I'm curious to learn).

I think the Vim Community needs to create a standard protocol for globally registering "which buffer belongs in which Vim Tab, window", so that all file switching/browsing/jumping plugins can consult that global table without having to reimplement the same searching logic (and in fact, some plugins like wintabs need to have their own custom logic anyways). Maybe wintabs is a good place to set an example here and establish a convention that all plugins can integrate with. Just a thought.

zefei commented 7 years ago

It's likely that I won't try to integrate with any of these use cases, but rely on hijacking buffer switching autocmds (the challenge here is a ton of edge cases). Setting up some protocol can work great (like VSCode's language server and debugger), but I think the vim culture will probably never agree to such a standard.

jordwalke commented 7 years ago

Wow, that would be impressive. I'm not sure how it could be done. How could a buffer switching autocommand detect that (in NERDTree or example) you hit <cr> for "open in new tab or wherever it's already open" vs. c-v for "open in new vertical split or wherever it's already open"?

zefei commented 7 years ago

@jordwalke I had some time this weekend and added experiment support for this. You can use the config let g:wintabs_switchbuf = 'useopen' or 'usetab' (see :h switchbuf for explaination) to get this behavior. It should work no matter you try to open file in current window or new split. However, like I said, this is a big hack (aren't all vim plugins so?) and there are tons of edge cases, so it's very experimental and please let me know if things break and how they break. Though some of the edge cases are nearly impossible to fix.

jordwalke commented 7 years ago

Can't wait to try!

jordwalke commented 7 years ago

Btw this feature seems to be working pretty nicely. You must have done some clever hacks! That might be worth open sourcing as a standalone plugin - something Vim desperately needs (and each plugin has to recreate it). Maybe your approach relies on Wintabs though so it can only be used with Wintabs (which is totally fine - all the more reason to use Wintabs!).

zefei commented 7 years ago

That's good to know! Unfortunately, my hack is very specific to wintabs, and not very reliable (rough assumptions and some race conditions ~).