7

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.

  1. 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.

  2. 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.

  3. 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)

puk
  • 16,318
  • 29
  • 119
  • 199
  • 5
    Not really a “Vim solution”, but why don't you use one workspace and one vim instance per project? To switch between projects you would then simply switch to another workspace where everything is set up the way you want it for that project. – beta Jan 06 '12 at 10:35
  • A lot of times I take results from plots and put them into Thesis, then I take the formulas from Thesis and put them into the Simulator. What I want is sub buffers. – puk Jan 06 '12 at 10:45
  • 1
    I wouldn't call 3 people "a lot of people". I actually don't understand anything to your workflow. Why do you always `cd`? Why don't you alias your `*.py` scripts or add their directory to your `$PATH`? Or maybe do everything in one Vim window and map your script to `` or whatever? – romainl Jan 06 '12 at 12:41
  • And what does your workflow has to do with Vim? Or even with project management? I'm seriously puzzled. – romainl Jan 06 '12 at 12:43
  • @romainl I just want more control of my tabs. – puk Jan 06 '12 at 12:50
  • In the workflow you described, the only place you are using Vim is when opening your .tex file. I don't see a mention of tabs, there. After that you just go back to the shell and jump from one folder to another for hours. 95% of your workflow is done in the terminal **outside** of Vim. A project-management plugin for Vim won't help you at all in the terminal. What will definetely help you is to add your scripts folder to your $PATH so that you don't have to do all that `cd` business: just stay in your .tex file's folder and launch your script from there. – romainl Jan 06 '12 at 13:00
  • @romainl I principally use `:bp/bn` (mapped to Shift + J/K) so I wanted to partition my files in to tabs. Obviously for the website I would have to use `:b fileName`. I gave up as I find the tabs almost completely useless in vim. I found out how to share the unnamed register across vim sessions, and how to remap the Gnome terminal next/prev tab shortcuts. I will just use the [far superior] Gnome terminal tabs (when used with fresh instances of vim). – puk Jan 06 '12 at 13:13
  • 1
    Please answer the questions of the people who try to help you so that they are able to help you in a more effective manner. You edited your question for clarification but your edit doesn't involve Vim. So please explain more precisely what you want to do with tabs and what's up with all the terminal stuff. – romainl Jan 06 '12 at 13:24
  • @romainl I changed the motivation section – puk Jan 06 '12 at 13:31
  • OK, you should have done that in the first place. Our first impression was right: what you want to do is not really possible so you have to use different Vim sessions in different terminal windows. – romainl Jan 06 '12 at 13:36
  • @yes I see that now, also I see that you had indeed mentioned `unnamedplus` – puk Jan 06 '12 at 13:39
  • It's like your question read my mind.. ! :) – Rahul Gupta Oct 26 '18 at 19:30

5 Answers5

6

I found out a way to do this. The vim tabs are near useless. Instead I used the Gnome Terminal Tabs.

  1. 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.

  2. 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

  3. Gnome Terminal Tabs Write a shell script to launch each vim instance as a new terminal tab. See here for instructions

  4. 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.

Community
  • 1
  • 1
puk
  • 16,318
  • 29
  • 119
  • 199
2

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.

zimski
  • 21
  • 1
1

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.

Macario
  • 2,214
  • 2
  • 22
  • 40
1

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • wrt bullet 1: they are in that gray area where they are somewhat related: my thesis generates results which are ploted, then I take some of the test code from those plots and plug back in my thesis, likewise, I use the code from my thesis in my simulator – puk Jan 06 '12 at 10:59
  • wrt bullet 2: I figured my computer can handle it =P But i will reconsider my approach. – puk Jan 06 '12 at 11:00
  • What I want is in each tab (except the website tab) to be able to do `:bn` (mapped to `Shift + J`) to cycle through the files as opposed to cycling through 600+ files – puk Jan 06 '12 at 11:01
  • I updated the question with an in depth explanation of why I am doing this. – puk Jan 06 '12 at 11:18
1

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

  • Also there is home brewed vimscript https://github.com/DXist/dotvim/blob/master/after/plugin/lighthouse.vim that I use to group projects by tabs. It handles project for each tab and buffer. Projects are configured in .vim/projects.vim file. – Rinat Shigapov Apr 14 '14 at 09:23