Integrating Vim with Gist at GitHub

MacVim.jpg

This morning I expanded my world considerably by happening across a Vim plugin for access to Gist. This is one of the services that I've been amazed at for a long while. GitHub is simply amazing, and I really should just give them money because I love what they are doing and want to support their work. But gists, in particular, are exceptionally cool.

Sure, there are a lot of places where you can throw up text and then look at it. But GitHub is so clean and focused on what they are doing, it's joy to use. So here's how I got it working:

First, follow the instructions on this page to download the plugin to your ~/.vim/plugin/ directory. You'll need to make a few additions to your ~/.vimrc file:

  let g:gist_clip_command = 'pbcopy'
  let g:gist_detect_filetype = 1
  let g:github_user = 'yourname'
  let g:github_token = '...big long hex number...'

and the instructions for getting your token are on the plugin page. Pretty simple stuff.

One thing I didn't like was the fact that when a new gist was downloaded, it was put into a split window. I don't like that. I have MacVim, and I open up new tabs and use them. So I changed the code in the plugin just a little. It was originally:

  1. if winnum != -1
  2. if winnum != bufwinnr('%')
  3. exe "normal \<c-w>".winnum."w"
  4. endif
  5. setlocal modifiable
  6. else
  7. exec 'silent split gist:'.a:gistid
  8. endif

and I changed line 299 to:

  1. if winnum != -1
  2. if winnum != bufwinnr('%')
  3. exe "normal \<c-w>".winnum."w"
  4. endif
  5. setlocal modifiable
  6. else
  7. exec 'silent edit gist:'.a:gistid
  8. endif

and everything worked just like I wanted it to. What an amazing little plugin for Vim! I can now edit, post, update, pull - all the things I'd like to be able to do on a gist, now from within Vim. What a treat.