Is there any plugin/way to manage multiple projects in Vim? [closed] - vim

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I always work on multiple projects at the same time. The breakdown of the number of files I have is as follows
Project | Files
--------------------------
Thesis 20
Simulator 50
Plots 30
Graphs 30
Website 500+
Having all of these files in one window is cumbersome. There are several options, and I will discuss their drawbracks, or dare I say their Achilles Heel.
Split Windows I could split vim into 5 windows, one for each project, but I might as well be coding through a pinhole. I have actually never been a fan of split windows, except for cases where you are constantly comparing and editing two related files. Also I don't find navigating in two dimensions as seamless as in the horizontal direction only.
Tabs Tabs, or rather viewports foolishly called tabs, seem to be exactly for this kind of problem, but they don't provide restrictions for buffers to use. For example, if I'm in my Thesis tab, I want to navigate only those 20 buffers, not all 500+ website related buffers as well. As I am saving these as sessions, it could potentially lead to problems if I accidentally switch to a website buffer in my Thesis tab, exit, then upon entering I have two website tabs. This is further problematic because I have set local directories (:lcd) for each tab.
Terminal Tabs Using the Terminal tabs ensures that that buffers in each tab remain independent. However, each vim session can no longer share information. I can't yank text from one terminal to the other (I suppose I could yank into the + register). I also can no longer use :buffdo on all the buffers. Also, I like the fact that I can save all of my vim tabs to a single session.
I know SO is anathema to public discussion, so I will instead ask if there exists a way to achieve the functionality I am striving for.
EDIT A good way to summarize what I need is to say that I want "sub buffers".
EDIT What I want to get out of the tabs in vim is the ability to more effectively use them as what they really are: viewports. I want to be able to have one tab exclusively for my Thesis section. In this section I will change the local directory to reflect it. Furthermore, I want to filter out the buffers in that table to only be a subset of all the buffers. Similarly in the Simulator tab I want to use it exclusively for my Simulator files.
Essentially what I want is the ability, through tabs, to run multiple independent sessions of vim, but still with some of the added perks (ie. sharing registers to be able to yank)

I found out a way to do this. The vim tabs are near useless. Instead I used the Gnome Terminal Tabs.
global registers To simulate using global registers, so as to be able to copy paste across different instances of vim, 'pipe' the system clipboard and the unnamed register together by adding the line set clipboard=unnamedplus to your .vimrc file. This has the effect of all yank/delete... operations being copied to the system clipboard. From there, other instances of vim will have access to it. Similarly, any copy pasting you do outside of vim, will now be stored in the unnamed register.
Gnome Terminal Tab Shortcuts The default shortcuts for going to the next and previous tabs are Ctrl Pg Up and Ctrl Pg Dn. Since I use Shift k and Shift j for my next and previous buffers, I mapped Ctrl k and Ctrl j to go to my next and previous tabs. Simply go to the Gnome Terminal > Edit > Keyboard Shortcuts
Gnome Terminal Tabs Write a shell script to launch each vim instance as a new terminal tab. See here for instructions
Vim Instances Finally, for each vim instance save a session file :mksession fileName
It's not perfect (for example, named registers can not be copied across terminals) but it is, in my opinion, much more representative of what a viewport (here called 'tabs') should do.
EDIT I have actually gone back to using vim tabs. I learned vim script, and mapped my keys so ShiftJ and ShiftK map to previous/next buffers and CtrlJ and CtrlK map to previous/next tabs. Then I downloaded the tabname script so I could set meaningful tab names, then modified the making of vim sessions to save tab names (see here), then switched from gVim back to Vim so I could use the full screen mode. It was a long arduous journey, but I'd like to think it was worth it.

I have this same issue for a long time, working the same time with several projects.
To solve partially this frustration, I have used this this plugin https://github.com/xolox/vim-session.
vim-session make easier the navigation between sessions and in each session we have a project.
After using this some weeks, I became frustrated because it needs each time you need to switch, all the changes of the current session's files need to be saved.
The best solution for me now is Spacemacs with Vim mode.
I really like the editing spirit that Vim offer and the experience is the same with Spacemacs + better project handling + better git integration.

I agree with ehamberg.
Vim's buffers are global so any grouping or splitting will only appear to work for a few minutes and actually break at the first occasion.
Instead use one Vim instance for each project. If you really need to share something you can always use the system clipboard. Try set clipboard+=unnamedplus to synchronise Vim's default register with the system clipboard.
But I'm wondering if your way of managing projects is rational:
In point 3 you write "I also can no longer use :buffdo on all the buffers.". Why would you use a command that works on all the open buffers across multiple different projects?
Do you seriously have 500+ buffers open at the same time? I know Vim can probably handle it but why do you open that many buffers? I do web development for a living and I rarely work on more than a dozen files in a given day, even on "large" projects.

BufExplorer plugin can group buffers by tab. CtrlP plugin can reuse buffer from another tab.

I was using multiple vim instances for working simultaneously with different projects but it was not satisfatory. I ended up having to many open tabs in my terminal.
I've been using vim-rooter, which is a simple plugin that will automatically change the working directory to the project root of the buffer you open, provided there is a .git dir at project root. It will only be triggered only by opening files with certain extensions, but that list can be customized. Works with ctrlp and any other plugin.

Related

In vscode, how to put editor regions inside tabs, and not the other way around?

I've been trying Visual Studio Code for a few days, and it's the first editor that I used in years that makes me feel I could switch from my beloved vim.
Now, it's hard to get used to new habits when you have years of muscle memory, but I'm trying to keep an open mind. There's one thing that's bugging me, though, and I could not find a way to get around: it's the fact that editor regions and tabs are "swapped". Let me explain:
In vscode, you define editor regions by splitting your screen, then each region can contain as many tabs as you want.
My problem is, that does not fit my workflow. Here's what my workflow used to be with vim, where regions are inside a single set of tabs (I mainly work with Django):
In a first tab, I've split my editor in half and I'm editing my models.py and forms.py side by side.
In a second tab, I've split the editor in half, I'm editing my views.py on the left hand side, and the right hand side is again split horizontaly, allowing me to edit multiple templatetags files.
In a third tab, I'm editing my main template, and I don't split the editor since the file may contain very long lines.
In a fourth tab, I'm editing several html files and the editor is split multiple times.
Etc.
That way, I can very quickly go to edit my models, then my views, then the templates, and start over in quick iterations.
With vscode, where the tabs are inside the fixed regions, not so much.
So my question is, what solution could I use? Am I missing a big feature here? Are there any extension that would allow me to get my old workflow back?
I'm also open to suggestions about new workflows.
As #romainl pointed out: the workflow is different, it doesn't work that way with VS Code (and I know, I'm a vim user, too).
The best you can get that is vaguely close to what you're used to is to consider VS Code windows as you did with vim tabs.
To give you an idea using your example:
You open a VS Code window and open side by side models.py and forms.py
You hit Ctrl+Shift+N (or Command+Shift+N on a Mac) and open a new window. There you open your views.py on the left and split the right one horizontally for the templates.
You open a new window again and repeat.
This way you can switch between different layouts with Alt+Tab
(or Command+Tab).
You could speed this up a bit by saving different workspace files for different files that you want open, because I think (not 100% sure) that saving the workspace also saves the layout.
There's a couple of annoying things with this approach though:
If you have multiple windows open in general (say, a browser, slack app and so on), they'll also appear in the list when you try to switch.
I'm not sure if the open folder will be remembered when opening a new window, but you can work around that by saving the workspace and opening it.
It's annoying but at least there's already a feature request about this ( https://github.com/Microsoft/vscode/issues/41486 )

Using vim to develop instead of Emacs on Windows

I have used Emacs for a long time, say, 6 or 7 years. And it seems that I got Emacs Pinky somehow. Now I am trying to switch to vim, and it's a very good editor, just like Emacs, except that I wonder how you guys develop with it.
Using Emacs with a buffer running shell, I code, compile, debug, profile or do anything. But vim is just an editor. I still don't know how to quick edit in command mode, where everything go back to stone age. Should I use other tools, like screen, as the environment, and vim just the editor?
FYI, I mainly work on Windows.
For those Emacs users wishing to have a Vim experience in terms of keyboard shortcuts and certain functions specifically designed to duplicate Vim behavior, the original poster may wish to consider using evil-mode:
http://www.emacswiki.org/emacs/Evil
In addition, the user may wish to configure his/her own keyboard shortcuts that make more sense based upon any physical limitations (e.g., pain in certain digits, etc.).
Finally, there is no requirement that a user keep his/her hands on the home row and stretch for the control/alt/command keys with a pinky. It is possible to type 100 words per minute or faster, hit keyboard shortcuts using two hands away from home row, and return to the home row blindfolded.

Buffers per tab in vim

Is there a way I can configure vim to remember buffers based on their tab?
I am currently working on two projects, and I have each project in its own tab, with its own local directory. To navigate through files I'm using FuzzyFinder.
The problem is that when I want to search through buffers, I get all the buffers from both projects.
Can I limit it to show only buffers from the current tab?
It may very well be that I am using a wrong approach here. If this is the case, what would be a better one?
Vim's tabs are not like most other editors tabs: they don't represent specific files or groups of files. They are just "views" allowing you to arrange buffers visually.
Vim's buffers are global and AFAIK there is no native way to bind them to specific tabs but I saw a "per-tab" fork of NERDTreee on Github the other day so it might be possible with some effort.
I use tabs only for quick edits and have usually one or two dozens buffers open. Most of them are hidden (:help hidden) and I rarely have more than 3 splits (only one file visible, most of the time). Buffer switching and file opening are done with LustyExplorer.
If I must work on two project I use two instances of GVim or two separate "GUI" windows in MacVim.
So yes, your approach is wrong (mine is most probably not perfect, either) but the culprit is the person or commity which decided to call Vim's tabs "tabs".
As a side note I find the "Rolodex Vim" idea quite enjoyable, there are two implementations on this page.

Better Tab Navigation in gVim

How can I get tabs in gVim to work like they do in most good IDEs? I say gVim specifically because that is the version of Vim that I use but I am open to alternatives.
I want the following things for my tabs:
Ctrl+Tab goes to the MRU (most recently used) tab.
Holding down Ctrl and then pressing Tab multiple times continues to change to the next most recently used tab every time you press Tab.
When ctags are built and working and you press Ctrl+], if this takes you to a different file it should open that file in a new tab or if a tab with that file is already open it should switch to that one.
Easy tab reordering with the mouse just by dragging them around.
I am posting all these as a single question because I am hoping there is a good single solution that will do all or most of these things instead of having to hack each customization in individually. I would think this would be the preferred behavior by most of us.
Vim has no built in MRU. There is at least one plugin for that, though, but I've never used it.
The tabs in Vim are not the same as the tabs in your IDE, they are more like perspectives. The equivalent of your IDE's tabs in Vim are buffers and "(split)windows". There are a number of ways to work with buffers including some native ones and a number of third party plugins. Some of these plugins have MRU-like features.
The Vim wiki has a bunch of pages about tabs.

more intelligent global bookmarks in vim

Here's how global bookmarks work.
Let's say I have two tabs in my vim session. One showing foo.txt, one showing bar.txt. I go to line 10 in foo.txt and hit mA
Then I go to the other tab, showing bar.txt. I hit `A, and the workspace on that tab opens foo.txt, putting my cursor on line 10.
So now I have two tabs, both showing foo.txt. This is less than ideal.
How I want it to work is, if one of my active workspaces on any tab is showing the file I the bookmark system is trying to navigate too, move my focus to that tab. If the file isn't open, sure - open it in my active workspace.
Is there any way to make this possible?
Thanks!
This is not a problem with Vim's global bookmarks. It's a problem with Vim's tabs.
In most text editors, tabs serve as a list of currently open files, but in Vim, the buffer list serves this purpose. If you think of a tab in Vim as being like a saved layout for split windows, then you'll meet less friction. This answer sums it up nicely, and I made a screencast to try and explain how tabs can be used.
Here is a script that answers your initial question. But as far as I'm concerned, nelstrom is right: tabs are not meant to contains the others files, but other layouts.
How do I jump to markers within different tabs in vim?

Resources