I’m working in an environment where I have several branches that I’m working on, and have the need to switch back and forth between branches regularly. To avoid updating things in the wrong branch (burned once too many times), I now shut down vim anytime I’m switching between branches and that means that I have to re-open the 2+ files that I was working on (I use tmux and vim) for the new branch.
I’d like a way to automate this for each different branch, so that sounds to me like maybe a special file in each branch with the commands for vim… or? Any ideas on how to do something like this?
BTW, I tried git-new-workdir which is cool (keep all the branches open simultaneously), but since we use submodules here, I haven’t figured that out yet.
Update: The -On option tells vim to open windows side-by-side (-on = stacked; -pn = tabbed). So if I have two files I want to open, then I just say:
vim -O2 filea fileb
and I’m off to the races.
Now I’ll just add a little shell script in each review branch and I get the basics easily.
Update-2: There’s even more; you can use the -c (command) option when invoking vim and tell vim exactly where you want things displayed. I have 5 files that I’m regularly opening from the command line when I switch branches, so I now have something like this:
vim -O2 <file-1> <file-2> -c "sp <file-3>" -c "sp <file-4>" -c "wincmd 2" -c "sp <file-5>"
I wind up with two files stacked vertically on the left (file-1 and file-5) and three files stacked vertically on the right (files 2, 3, and 4). Just another way to save time and keystrokes with vim!