Real Ultimate Programming

The Home for People Who Like to Flip Out and Write Code

Using Bcvi From OS X

When it comes to text editing, it doesn’t get much better than vim—and by extension, MacVim. If this is the first time you’ve heard of vim, or the first time you’ve seriously considered using it, please stop now and go read Coming Home to Vim, by Steve Losh1. That captures the Zen of Vim better than anything else I’ve read.

If you’re still around (or back), then congratulations: you have great taste in editors. Now on to one of the most irritating things about vim: getting your vim all tricked out with just the right set of plugins, color schemes, and keybindings, then getting stuck on a remote server somewhere with a vanilla version of vim, or maybe even a different vi clone, like nvi. Enter bcvi.

bcvi is a clever little tool that basically copies the file you want to edit to your machine, invokes gvim on it, then copies it back when you are done. Presto: you get to edit in the comforts of your own, highly optimized vim environment.

All you need to do to get bcvi is install it via CPAN; it even comes with a couple of helper commands to give you handy shell aliases, etc. But if you’re running OSX , oh-my-zsh (if you’re not, go read Steve’s My Extravagant Zsh Prompt for a good explanation of just how awesome it can be), and MacVim, then there are a couple of things that you’ll probably want to do.

As an aside, you might want to update CPAN so it stops nagging you every time you try to install something. The default perl that ships with OSX is under /usr/bin, so upgrading CPAN is going to require sudo. It’s also rather old. If you’d rather, you can simply install a current perl via Homebrew. This will get you up-to-date and allow you to upgrade CPAN without needing sudo. You could also look into local::lib, which I’ve used with success on servers. The instructions I used (NOTE: some of these are probably unique to my box, but I don’t have a spare handy to test) are:

1
2
3
$ brew tap homebrew/dupes
$ brew install perl
$ brew link --overwrite perl

With that out of the way, here’s how to get started with bcvi on a Mac:

  1. Install bcvi. This is as simple as install App::BCVI from the CPAN prompt.
  2. To make bcvi use MacVim (or possibly even work, if you don’t have an X-based version of vim), you need to symlink gvim to mvim. Since I have my mvim situated in /usr/local/bin, that’s where I put the gvim symlink to it, as well.
  3. Get those lovely aliases. Execute bcvi --add-aliases. NOTE: This only adds them to .bashrc, so if you’re using ZSH, you need to copy and paste them to your .zshrc.
  4. Start the listener process. This is as simple as bcvi --listener &, but I would never remember to type this until the first time I tried to use bcvi and it errored out. Instead, I use a launchd job. You can get it from this BitBucket repo. If you’ve never used launchd jobs before, instructions are included in the README.
  5. Install bcvi on the remote servers where you’d like to use it using bcvi --install hostname. This will install bcvi in $HOME/bin, so permissions shouldn’t be a problem.
  6. Finally, I like to add an alias so I don’t have to type bcvi --wrap-ssh -- hostname every time I connect to a server and want to have access to bcvi. I added the following to my .zshrc:
1
alias ssh-bcvi='bcvi --wrap-ssh --'

At this point, you should be able to ssh-bcvi to your remote server, find the file you need to edit, and vi filename to edit it in the comfort of your own vim.

Back to flipping out…

  1. As a matter of fact, just go read everything Steve writes. I steal ideas from him all the time.