My World Through Vim Colored Glasses
I like Vim. I like it a lot. I’m sure Emacs is good to, but I’m flying the Vim flag. I used to use a Big Enterprise IDE™ but I have found that Vim gives me a lot of power without using all of my memory to run an IDE.
Through all my years of experience with Vim, I have become more and more proficient with the Vi keybindings. For example I used to rely on the arrow keys when I started using Vim, but now h/j/k/l have become my preferred way to navigate. I find myself exiting insert mode more often than not to accomplish tasks, compared to spending almost all of my time in insert mode.
With this ever growing proficiency, I find my interactions with everything else…a bit lacking. My terminal feels slower, my IRB sessions feel slower, I wanted to be able to use my Vim-fu everywhere. After some digging and investigating I found ways that I could do it.
There are a few places where you will have to change, but all you have to do is add a few commands to some dotfiles.
Zsh
I use Z shell with Oh my Zsh which is a really powerful set of customizations that really make using Zsh both pleasant and powerful. To make it more powerful and enable the Vi keybindings you have to add the following to you .zshrc file:
bindkey -v
Then you can either source your changes with . ~/.zshrc or using the source ~/.zshrc commands. Now
you will have access to the Vi keybindings while using your shell. You will not have to worry about
insert mode as much because since the goal is to type commands into the shell you will be automatically
started in “insert mode”, but if you hit the up key (or with the Vi bindings <esc>-k) you will be
placed in edit mode where you can use keys like w to go forward one word, dw to delete a word, etc. All
the productive keybindings that you know from your text editor in your shell.
You might be tempted to fire up some programs and try out the new bindings in them, but alas it is shell only…or is it?
Most Interactive Programs
To get the Vi bindings set up on most other programs (I’ve found debuggers don’t really work this way) you have to create and edit two more dotfiles.
The first file is the ~/.inputrc file. This file is used by OS X 10.4, but hey let’s go ahead and make
sure this works all around. Simply create the file and add:
set editing-mode vi
Now create the ~/.editrc file and add:
bind -v
Tada! Now you have Vi bindings in interactive terminal programs like irb, mysql. postgres, etc.
Bonus: Ditch your Caps Lock
Using PCKeyboardHack you can change your useless Caps Lock key into another esc key (less reaching during your Vi hackery). The link contains detailed instructions.
Breathe Easy
Enjoy your new interface to all your favorite terminal interfaces. You should find that not only is your ability to get stuff done has increased, but also you should find that you learn more about the magic of Vi keybindings.