Being a proud citizen of HJKL-land

Over the past year, I’ve been working hard to indoctrinate my fingers to become better citizens of HJKL-land. To be a good citizen of HJKL-land, one must train in the way of Vim: resist all urges to move the hands to the arrows keys or to the mouse; strive to keep your fingers on the home row; think in terms of text motions instead of simple keyboard motions; and, of course, endeavor to remove all wasted motion in one’s daily text editing.

Being a citizen of HJKL-land is indeed a rewarding experience.

But it wasn’t easy. Sure, one could make progress by reading a book watching some screencasts, installing a couple of plug-ins and even reading about Vimscript. But just using Vim occasionally isn’t going to help indoctrinate you to be a good citizen. Until one starts using Vim for the essentials, it just isn’t going to click.

For a developer, this means being in Vim-mode for the tools you use daily: your shell, your terminal, your web browser (don’t laugh, just time how much time you spend in your web browser reading Stackoverflow each day) and your other IDEs (for when you can’t use Vim).

There are many excellent tutorials out there about Vim. This isn’t one of them. Instead, the point of this post is to illustrate how to get some of the tools that you use daily into Vim-mode. Spending as much time in Vim-mode (or Vim-like-mode) as possible is the best way to train.

zsh

zsh is my current shell right now. The magic incantation to turn Vim-mode on for zsh is bindkey-v. However, just turning that on isn’t going to buy you much. In fact, it might even make you less productive because a lot of the keyboard shortcuts that you are used to might no longer work (e.g., reverse-search of commands).

Instead, I suggest using zsh with the useful .oh-my-zsh framework. I have a simple fork of at https://github.com/vazexqi/oh-my-zsh/. I added some useful features to enable incremental search of history. The details are in my modified vi-mode plug-in file.

Enable the vi-mode plug-in by adding it to the plugins variable in your .oh-my-zsh genarated .zshrc file.

plugins = (vi-mode history-substring-search)

If you are still using bash, then I recommend subscribing to Tom Ryder’s Arabesque blog. He is an active Vim user who also happens to use bash as his shell. In fact, my tip for tmux comes from him.

tmux

To prevent a proliferation of tabs or windows, I manage all my terminal sessions using tmux. I won’t have time to go into all the features of tmux so I would recommend reading Pragmatic Tmux which is concise introduction to the features of tmux.

Here are some tweaks that I put into my .tmux.conf file to make it mimic Vim. The top portion corresponds to tweaks to simulate Vim motions for selecting different panes. The bottom portion corresponds to tweaks to make tmux’s selection more behave like Vim. I’ve credited the original authors where possible. For my entire .tmux.conf, please refer to this gist.

# Simulating Vim motions
########################

# splitting panes
# START:panesplit
bind v split-window -h
bind s split-window -v
# END:panesplit

# moving between panes
# START:paneselect
bind h select-pane -L 
bind j select-pane -D 
bind k select-pane -U
bind l select-pane -R 
# END:paneselect

# Pane resizing
# START:paneresize
bind -r H resize-pane -L 5 
bind -r J resize-pane -D 5 
bind -r K resize-pane -U 5 
bind -r L resize-pane -R 5
# END:paneresize

# Vim-style keys in select mode
###############################

# enable vi keys.
# START:vikeys
setw -g mode-keys vi
# http://blog.sanctum.geek.nz/vi-mode-in-tmux/
# https://github.com/sjl/dotfiles/blob/master/tmux/tmux.conf
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
bind -t vi-copy Escape cancel
# END:vikeys

Pentadactyl

Pentadactyl is a browser add-on for Firefox that enables Vim-like motions for browsing the web. Because browsing the web isn’t exactly like editing text, there is some impedance mismatch between some of the key mappings. But for the most part, it’s pretty intuitive. It’s also one of the main reasons why I tolerate Firefox as my main web browser.

Chrome has Vimium but it just feels like ersatz Pentadactyl.

If you have heard of or use Vimperator before, Pentadactyl is similar. There is an FAQ entry discussing the (political) differences, which I won’t get into.

There are a ton of features for Pentadactyl so I am going to list my top three.

  1. Follow hints: Type ‘f’ on your keyboard and all links are immediately marked with unique key sequences. Typing out a key sequence (very short; about 2 characters) will open that link. For more information, see this help entry.

  2. Quickmarks: Assign one character shortcut keys to your favorite bookmarks. For instance, I assign ‘G’ for Gmail. I can easily open GMail in the current tab by executing goG. Or I can open it in a new tab by executing gnG. go stands for “open in current tab” and gn means “open in new tab”. I have several quickmarks for Gmail, Github, Google Voice, Facebook, Twitter, etc. This saves me tons of time each day.

  3. Jump to top of page and bottom of page quickly: Just do as you would for Vim. Hit gg for top of page. And G for the bottom of the page. No need to use the scroll button on your mouse of hit the page up keys repeatedly.

Vrapper and IdeaVIM

I am bit ashamed to admit that I use these last two tools but, hey, I code in several JVM languages (Java, Groovy, Scala) and without an IDE with smart auto-completion of libraries, it is a pain to type everything manually.

Vrapper extends the Eclipse text editor with Vim-like input scheme.

IdeaVim, is the same, except that it works for IntelliJ IDEA.

Both of these do not fully emulate all the Vim shortcuts. However, they are pretty decent. Vrapper, in particular, has an embedded version of Tim Pope’s Surround. If you use Sublime Text as your text editor, then I would say that both these plug-ins are comparable to Vintage Mode..


And that’s my list of tools and how I tweaked each one to behave more Vim-like. Every little tweak helped me embrace Vim more and train my fingers until the motions become second-nature. If you know of other tools and how to make them behave more Vim-like, I’d be interested in hearing more.


comments powered by Disqus