How I

Henrik Nyh

Web developer

Stockholm, Sweden

Who are you and what do you use Vim for?

I’m Henrik Nyh (@henrik), a Swedish web developer. I blog at The Pug Automatic. I work for, mostly doing Ruby on Rails.

I switched to Vim from TextMate 4 years ago. I would describe myself as a bit of a power user – I’ve written a few plugins (also these tiny ones), have invested some time into my .vimrc, and I like to keep learning. Though I guess the concept of a “power user” is tricky with Vim – the floor is high and I’m not sure if there’s a ceiling…

I use Vim at work and for personal projects writing mostly Ruby, CoffeeScript (JavaScript), Sass (CSS) and Slim (HTML). Some Elixir for fun.

I also use it for blog posts (powered by Octopress) and notes from meetings and otherwise (I type text in a terminal to open my folder of notes).

It’s also my scratchpad for code experiments and exploration – more about that later.

I use terminal Vim (currently version 7.4.712) via Homebrew on OS X, or in a Ubuntu VM, often within a tmux session.

There are times when I’m not faithful to Vim. I use Pages for quick rich-text stuff, Soulver occasionally for calculations, and Stickies for some kinds of notes. I don’t go so far as to use Vim to edit every form field or email.

Introduce us to your Vim config.

My .vimrc is a mere 8 lines, but only because I’ve extracted stuff to keep things tidy. There’s quite a lot in there all in all.

I started out with Janus, a “Vim distribution” of plugins and configuration. I’ve since replaced and rewritten things to the point where I don’t think you could tell how it started.

Putting your dotfiles in a public repo, such as on GitHub, is quite valuable, I think. You can experiment more freely when it’s easy to roll back to a previous state, and you can share your config with others. The fact that you know it’s publicly available helps keep it relatively tidy.

Although I have a lot of Vim configuration, I try not to rely on it too much. I will sometimes pair with someone with a different configuration, and sometimes I use a bare-bones Vim on some server somewhere. So I take a bit of pride in knowing Vim well enough that I can get by without my configuration, and that I can write some one-off mappings and configuration as needed.

That said, I have configured Vim so much that it’s hard to know where to start…

Plugins and configuration

I use , for my leader key. It’s not the default (\ is), but it’s a common alternative. On a Swedish keyboard, \ requires two modifiers (Shift + Opt + 7) where , requires none, so it’s a no-brainer.

I use ctrlp.vim for fuzzy file navigation. It’s easy to install (pure Vimscript) and has some nice features (e.g. <c-p><c-p> to reopen the last search). I don’t love how it sorts files, though, so I might replace that part of it some day.

For project search, I mostly use git-grep-vim.

I use NERD tree to orient myself in projects, and for some file management. I recommend setting up a mapping (I use ,N) to show the current file in the tree (:NERDTreeFind or something more complex) – that can be quite convenient. NERD tree has a lot of handy shortcuts – just hit ? in the NERD tree window to see them.

Since I usually develop inside tmux, I run my tests in a tmux split using Vimux and Turbux.

I’m a big fan of CamelCaseMotion.vim. In Vim, w is the “small word” motion and W is the “big word” motion. This plugin introduces ,w (and ,b and ,e) as an even smaller word – namely the subparts of camelCase or snake_case. With your cursor at the start of the text one_two.three four, the cW command will replace the one_two.three part. cw will replace one_two. And c,w will replace one. I use this several times a day.

One of my many mappings makes :W works just like :w, to save a file. I can’t seem to learn to release that Shift key when I should.

I’ve remapped some built-ins. For example, as a fan of soft-wrapping, I’ve made arrow keys and j/k move by screen lines instead of file lines.

I manage most plugins with pathogen.vim and Git submodules. It works OK, but Git submodules are a bit of a pain. I didn’t like Vundle (another plugin manager) last time I tried it, but I’ll give it another shot some day. I think my main complaint was that neither Vundle nor my repo kept track of the version of each plugin, which I’m sure can be achieved with Git submodules or (preferably) in some other way.

The plugins for pathogen.vim go in ~/.vim/bundle, but I also have a bunch of tiny single-file plugins in ~/.vim/plugin.

One piece of configuration that might be mildly controversial is that I haven’t disabled arrow keys. I think they’re fine. The physical layout on my keyboard maps to how they move on screen. The mnemonics are great. While there are certainly some arguments for navigating with h/j/k/l, I see it mostly as a kind of shibboleth – a statement of identity and belonging. It supposedly started out as a technical limitation anyway.

Color scheme, status line and cursor


I use Drew Neil’s “blackboard” theme. I think I used essentially the same theme in TextMate. I’ve tried others but none that I liked better.

Though it’s not a part of the theme as such, I have a small plugin to highlight bad whitespace in red.

My status line is quite simple – I don’t think it’s far from the default.

Screenshot in insert mode

Since I use iTerm for my terminal, I can change the cursor in insert mode.

What have been the most useful resources for you to learn Vim?

I blogged about my switch from TextMate to Vim four years ago.

I had been Vim-curious for a while but the “start with an empty .vimrc” strategy never worked for me. I still see it advocated, and I’m sure it’s a good fit for some, but it wasn’t for me. So if you keep giving up on Vim because you feel less productive than in some other editor, try starting out with “training wheels” in the form of some distribution like Janus, or someone else’s dotfiles. Then when you know more, feel free to start over with an empty .vimrc if that’s what you want.

When a new tool really grabs me, I will spend a few weeks reading all about it. Vim was one of those tools. So initially I read a ton of blog posts and dotfiles, watched many of Drew Neil’s Vimcasts and read his “Practical Vim” (I have a blurb!), read the :help for whatever struck my fancy and so on.

I’m not monomaniacal about Vim anymore, but I will still dig through the :help occasionally to learn more about some topic, and I keep an eye out for things to learn when pair programming, on Twitter or in blogs. I sometimes check the :help for some plugin I’ve used for ages and discover useful things.

Share a piece of Vim script you’ve written and talk about what it does.

I mentioned using Vim for code experiments. I have some stuff around this.

If I want to quickly try out some Ruby code, say, I open a new buffer and use one of my commands to quickly set the filetype. There’s :FR for Ruby, :FV for Vimscript, and so on. There’s also :F <filetype> with autocompletion. It slightly beats :setf ruby.

And to run those Ruby scripts from within Vim, I wrote a vim-ruby-runner plugin. I just hit ,r to see the output in another split. Though I’ve been wanting this in Elixir as well, so I should probably find a more general plugin, or adapt this one.

I also have a vbr shell alias to launch Vim with the Ruby filetype already set for the open buffer, though I rarely use it anymore:

alias vrb='vim -c "setf ruby"'

And in a similar state of disuse, I have a :Lab command to open a new buffer with the Ruby filetype set, some boilerplate already in place, and the editor in insert mode.