Tmux and Vim, get married.

Vim and Tmux are an excellent choice for a modern develpment environment on Mountain Lion. I describe how to combine create such an environment using homebrew.

Using a rad, aesthetically pleasing, and efficient development environment is so crucial to having a good day. I’m going to describe mine, and give you the set of links from which I’ve assembled this confection. We’ll be using:

Vim & MacVim First, one must install MacVim. Duh. With homebrew. Duher.

  $ brew install macvim

Now we’ve got MacVim, which is a gui flavored Vim. It’s wildly useful, and a bit more comfortable for those of us accustomed to cmd-tab’ing through our applications. Still, we’ll want Vim.

The Vim that comes stock with OSX sucks all sorts of members. Welp, there’s a better way. Install Vim with homebrew. As it’s a dupe of a stock OSX application, we need to tap homebrew/dupes, and install from there.

Installing Vim from hombrew/dupes can be sort of tricky, though. I wasted about an hour, smashing my face into something solid, unable to understand why homebrew was exploding while trying to compile Vim. I’m still not sure what was happening, but I know how I fixed it.

I manually changed what version of Vim is fetched from Google’s code repo. You should too, until that shit is fixed.

  $ brew tap homebrew/dupes    
  $ vim /usr/local/Library/Taps/homebrew-dupes/vim.rb  
      
  # At the very top, replace url
  url 'https://vim.googlecode.com/hg/', :tag => 'v7-3-617'

  $ brew install homebrew/dupes/vim

Boom-Bapper!

I still bounce back and forth from MacVim to Vim, though I’m getting more in the habit of sticking to Vim. MacVim is tops, though.

Janus Now, as anyone who’s ever opened Vim can tell you, it’s terrible

until you add some plugins to it. A tedious affair. Made less tedious by something called Pathogen. Made lesser tediouser by a plugin manager called Janus. Let’s go with Janus.

  $ curl -Lo- https://bit.ly/janus-bootstrap | bash

More Plugins!!! Janus is extremely easy to extend with additional plugins

by using Pathogen. We can create a directory called ~/.janus, into which we can install all sorts of code loot.

  $ mkdir ~/.janus $ cd ~/.janus

Now, let’s start downloading!

tComment - nice shortcut for commenting things

  $ git clone https://github.com/tomtom/tcomment_vim

Powerline - looks pretty

  $ git clone https://github.com/Lokaltog/vim-powerline

Solarized Theme - looks pretty

  $ git clone https://github.com/altercation/vim-colors-solarized

Eunuch - use things like “:SudoWrite”

  $ git clone https://github.com/tpope/vim-eunuch

Chool. Next up, let’s personalize Vim a bit, using Janus’s vimrc scheme. If you’re not familar with how Vim stores it’s setting, they’re traditionally in a file called ~/.vimrc. Janus does it a bit different, using a .vimrc.before, and a .vimrc.after. They both live in your home directory. The reason they remain separated is so that one can override Janus, before AND after.

  $ vim .vimrc.before

  " Add this line, because tComment is better call
  janus#disable_plugin('nerdcommenter')

  $ vim .vimrc.after 
  " Copy in a .vimrc boiler plate

I found a pretty good boiler plate for .vimrc.after at net.tutsplus, though mine has a few additions. It’s here, if you’re interested. Which you ought to be, as I’m using the Solarized color scheme.

Also, we’ll need to install a patched font so that Powerline will function properly. Powerline draws fancy characters in the status bar of Vim. This one is my favorite —> https://gist.github.com/1627888

iTerm2 Now, we can do all sorts of fanciful things. I recommend dropping

OSX’s terminal emulator for iTerm2. It handles some stuff just a little bit better. Download it here.

Once we’re iTerm2-ing it, create a new profile for yourself at Preferences

profiles. Next, download Solarized for iTerm2 here. Once that’s done, we can load a theme into iTerm2’s color presets. Navigate to the “Colors” tab, and expand “Load a preset”. You can import your preferred flavor of Solarized. Once it’s imported, set it using “Load a preset”.

Navigate to Preferences > Text, and change your font to whichever patched font you’ve settled on for Powerline. Then, uncheck “Draw bold text in bold font”. Double check that your terminal type is set to “xterm-256color” in Preferences

Terminal. Finally, in Preferences > Keys, set the left option key to +Esc.

Phew…

zsh/oh-my-zsh Bash has been a good friend. However,

zsh is better. And it’s so easy to install with oh-my-zsh.

  $ curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh

Now, we’ve got a nice copy of zsh, prefab’d with a bunch of cool plugins.

Zsh is easily customized with a ~/.zshrc. As always, when working with homebrew packages, we’ll need to make sure they’re first in our path. Easily done by adding the following to .zshrc:

  # $PATH # This puts homebrew packages first in path
  PATH=/usr/local/bin:/usr/local/sbin:$PATH

Tmux The cherry on top; Install Tmux.

  $ brew install tmux

Copy/Paste can get weird, so we’ll use homebrew again:

  $ brew install reattach-to-user-namespace

Add the following to ~/.tmux.conf

  # zsh is kinda tight set-option -g default-shell $SHELL

  # copy and paster set-option -g default-command
  "reattach-to-user-namespace -l zsh"

  # look good set -g default-terminal "screen-256color"

  # act like GNU screen unbind C-b set -g prefix C-a

  # a mouse set -g mode-mouse on setw -g mouse-select-window on setw -g
  mouse-select-pane on

  # act like vim setw -g mode-keys vi bind h select-pane -L bind
  j select-pane -D bind k select-pane -U bind l select-pane -R bind-key -r
  C-h select-window -t :- bind-key -r C-l select-window -t :+ unbind [ bind
  ` copy-mode unbind p bind p paste-buffer bind -t vi-copy v begin-selection
  bind -t vi-copy y copy-selection

  # after copying to a tmux buffer, hit y again to copy to clipboard bind
  y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"

A great article about setting up the “Text Triumvrate” can be had at drbunsen.org. I highly recommend reading it.

Syncing it all with Dropbox Now, we’ve spent a bit of time creating all

of these configuration files. Wouldn’t it be nice if we never have to do that again? Yes. Use Dropbox.

We can symlink every configuration file from Dropbox, stashed in a hidden folder. Move all that junk, and begin symlinking it to your home directory.

  $ ln -s ~/Dropbox/.dotfiles/.vimrc.after

We can even put things like .ssh keys in there, and never fear that we’ll lose something. Only that Dropbox will go bad, like Facebook, and try to ssh into all of our shit, the better to be able to direct market to the masses.

I can’t wait ‘till Facebook dies.