VI everywhere, what's your superpower
By Michael Milewski
Abstract
“Once you learn VI bindings, they will be stuck with you for life”
and you will want to use them everywhere! This is an exploration of all the places you can use them, from the command line, language REPL to your database console, browser and program input, even ways of adding them to places they don’t exist. Even if VI has always been on your TODO list, some tips on how to get started in learning VI bindings from someone who is pragmatic and does NOT use VIM as their editor, just VI bindings in every place you would least expect.
The Ruby version
This presentation at June Ruby Melbourne meetup was given with a bit of a ruby spin. Talk can be watched here
## Key takeaways
-
by default you are using
EMACSbindings on your command lineset -o | egrep -e 'emacs|vi ' emacs on vi off -
you can turn
VIbindings on with the following commandset -o vi set -o | egrep -e 'emacs|vi ' emacs off vi on -
you can now use all the handy VI bindings like the following
w # jump a word 5w # jump 5 words d2w # delete 2 words $ # jump to end of line (like regex) ^ # jump to beginning of line (like regex) ct; # change to `;` character u # undo y$ # yank (copy) to end of line p # paste what you have yanked h j k l # h - left, j - down, k - up, l - right -
How to learn VI bindings? come up with a script like above and just rote learn it. Then when someone teaches you a new binding, come up with a script and learn to use it too. It only takes 5 minutes a day of practice for about a week #7DayCodeChallenge and you will have it in muscle memory.
Script for below console demo
- Jump
5w5 words forward, $jump to the end of the line,^jump to the beginning of the line,d5wto delete 5 words,Pto paste at the cursor,pto paste multiple times after the cursor,uto undo multiple paste commands.

-
So can I use this for the input of my program?
Rubyruby -e ' require "readline" while line = Readline.readline("> ", true) p line end'Pythonpython3 -c ' import readline while True: line = input(":") if line == "stop": break print("%s" % line)'
Script for below console demo
- Using
y Wto yank (copy) a word, - then
Pto paste it at the cursor - and
pto paste it after the cursor - and finally
uto undo one of the pastes.

-
Hey I am using a programming language REPL (Read-Execute-Print Loop) or a DB console and I want VI bindings too!
just got a 100x speed improvement in my ruby irb
— Michael Milewski (@saramic) May 9, 2013
set editing-mode vi
and
cat >> ~/.editrc
bind -vhttp://t.co/c26qxc4tQW# ~/.editrc bind -v -
But I am on someone elses machine, or on a server in production and don’t want to set that up!
Sure just hit
<ESC> <ENTER> <ESC> <ENTER>and magically VI bindings will be there
-
What else is there?
/ # to go into search mode v # to take your command line straight into a full VI editor, when you # exit the command runs
Script for below console demo
⎋(⎋ = ESC)ESCto go out of insert mode and go into normal mode/to search,/devto search for last command in history with textdev↩(↩ = ENTER)ENTERto run commandvto open VI on the command$to jump to end of lineBto jump back a word10~to swap case of next 10 characters (upcase):x↩to quit VI and execute the command

-
I am using
mongoorelxirornodewhich don’t use readline so I can’t get VI bindings 😢Use rlwrap - https://github.com/hanslub42/rlwrap
brew install rlwrap rlwrap --always-readline mongo rlwrap --always-readline node rlwrap --always-readline iex -
hey what are you using to show which keys are being used?
Keycaster https://github.com/keycastr/keycastr
brew cask install keycastr ^ ⌥ ⌘ k # to toggle it on/off
In the future
I am hoping to give this talk with a python flavour at the upcoming Melbourne Python Meetup in Melbourne - Monday 4th March
Authored By:
Michael Milewski