Search code examples
windowsvimvigedit

gvim: go to a specific file with multiple windows and multiple tabs open


I am in the process of shifting editors from gedit to gvim. In gedit, when I have multiple gedit windows open, each having multiple tabs, I can click Documents which will list all files in all tabs and windows open and I can go to any one of those by clicking from the list.

How can I do this in gvim? The Buffers button in gvim lists only the files open in the current window.

Thank you!


Solution

  • GVim is a single window program. If you have two GUI windows you have two separate GVim processes that can't really talk to each other.

    Switching from a "normal" editor to Vim is not a walk in the park: you'll have to adapt to Vim's mindset for your switch to be successful.

    Vim's "windows" and "tabs" are badly named and provide much confusion among newcomers.

    In "normal" editors, a tab (or a GUI window for those without tabs) is a 1:1 representation of a file and a GUI window is a collection of tabs/files. The system is deterministic: as long as you didn't close it, you can equate the first window with Controlers/, the second tab of the second window with Models/User.php and so on. Because that "normal" editor is a multi-window program and all those tabs and windows are children of one process it's easy for the main process to provide a list of all of its windows and tabs.

    In GVim, the two GUI windows are created by two separate processes: GUI window #1 as no knowledge of GUI window #2. Furthermore, Vim's concept of "windows" and "tabs" is not deterministic at all. A "window" is only a view of a buffer and this buffer can be any buffer currently in memory. A "tab" is a collection of windows and its name is automatically set to the buffer currently displayed in the active "window". In an extreme scenario you could end up with the same buffer displayed in x windows in y tabs.

    So, because of GVim design, I don't think it's possible without a lot of work to mimic Gedit's behaviour.

    Because it's too easy, specially for new users, to mix up their "buffers", "windows" and "tabs" I'd advise you to stay away from "tabs", at least for a moment, and learn to use "buffers" and "windows" to their fullest.

    Vim's default behaviour is to ask you to save the current buffer before replacing it in the current window with another buffer. This, I think is the reason so many people turn to using tabs in Vim. set hidden and set switchbuf=useopen solve this "problem" and allow you to open many buffers in the same window. Switching buffers is super easy with native tools: :sb <tab> and sexy/powerful with 3rd party tools like CtrlP or others. If you are used to having different parts of your project in different windows (one for Controlers/, one for Models/ and one for Views/, for example, or one for the backend and one for the frontend) you can use Vim's tabs for that.