Useful MacVim Script

Average reading time is

A wonderful little script I use on a daily basis is the MacVim shortcut below.


if [ $# == 0 ]; then
  mvim --servername $(basename $(pwd)) \
       --remote-tab-silent "$@" 1>/dev/null 2>&1

I have this saved as v in my ~/bin directory, and here's how it works:

~/code/tsaleh/tammer-saleh$ v Gemfile

Opens Gemfile in a new macvim window:


~/code/tsaleh/tammer-saleh$ v 

Opens in a tab in that same window, since we're still in the tammer_saleh directory:


~/code/tsaleh/tammer-saleh$ cd ~/bin
~/bin$ v git-fml

Opens git-fml in a new macvim window, since we're in the ~/bin directory:


The magic is in the pwd call, which names the main window the same as your current directory. The result is a natural flow of tabs being grouped by the project you're working on, and it works quite nicely.

Feel free to submit corrections via github