This page intentionally left blank.

VI everywhere

What's your super power

  • Michael Milewski
  • @saramic
  • https://failure-driven.com
  • Developer at Fresho!

VI via readline

more like it!

What is VI

an editor

Why VI is called VI?

ex short for EXtended

ex is a line editor

VI = VIsual

shortest unambigous abbreviation

VIM = Vi IMproved

How to exit the Vim editor?

:q    # quit vi
:wq   # write file and quit
:q!   # quit vi not save
:x    # write and quit

Demo - what is VI

vi            # open vi editor
i             # insert mode
              #   enter text
ESC           # normal mode
              #   special commands
h j k l       # ⬅ ⬇ ⬆ ➡
:             # ex mode - command mode
/             # search
n             # next match
:s///         # substitute
:q!           # quit without saving

So far

  • Vi where there is readline
  • Vi in the editor
  • what about everywhere?

Vi on the command line

Demo - vi on command line

set -o vi
ESC             # normal mode
/               # search
cw              # change word
u  .            # undo and redo
^  $            # beginning and end
w  W            # word and whitespace word
b  B            # back a word
y               # yank (copy) to end
p               # paste
ct<char>        # cut to character

get me out of here

set -o emacs    # get me out of here

Emacs

set -o | egrep 'vi |emacs'

emacs           on
vi              off

emacs shortcuts

CTRL A        # beginning of line
CTRL E        # end of line
CTRL R        # reverse search

But where is the super power?

"2. That having no choice but to use vi early in my career would mean that I can never leave those keybindings behind."

@anaulin https://anaulin.org/blog/things-nobody-told-me-about-being-a-software-engineer/

hey how do I learn it?

Rote

Rote?

  • @AdamCuppy
  • Mechanically confident
  • https://youtu.be/Btsx9YzhJVM

Pauly principle

if you repeat an action enough

it will become automatic

therefore effortless

Rote learning

  1. come up with a drill

    set -o vi
    python -c 'print("hello")'
    <ESC> k $ b i
     Python
    <RETURN>
    set -o emacs
    
  2. repeat

PRACTICE, PRACTICE, PRACTICE

The label said EVERYWHERE!

not just readline and command line!

Postgresql and Mysql database

  # psql

  cat >> ~/.inputrc
  set editing-mode vi

  # mysql

  cat >> ~/.editrc
  bind -v

Vi anywhere there is ReadLine

Your super power?

  • vi shortcuts?

  • touch typing?

  • problem solving with TDD?

  • new language or framework?

    PRACTICE, PRACTICE, PRACTICE

What we learnt?

set -o vi         # get into vi mode
set -o emacs      # get me out of here

ESC               # go into "normal mode"
/                 # search for a term

**Navigation**
h j k l           # ⬅ ⬆ ⬇ ➡
gg                # top
G                 # bottom
^                 # begninning of line (~ regex)
$                 # end of line        (~ regex)

**Insert mode**
    a  A          # append after cursor/end of line
    i  I          # insert before cursor/beginning of line

What we learnt?

**Editing**
    .             # redo
    u             # undo
    cw            # change a word
    x  X          # delete character/previous character

w  b              # move word forward / backward
w4 b4             # move 4 words forward / backward
W  B              # move whitespace word forward / backward
ct <CHAR>         # change to '.' character
yw                # yank (copy) word
y4w               # yank 4 words

v                 # open vi editor

Thank You

  • Michael Milewski
  • @saramic
  • https://failure-driven.com
  • Developer at Fresho!
  • https://github.com/saramic/vi-on-the-command-line

Questions?

Where do you wish there was VI bindings?

  • everywhere
  • iPhone
  • Browser
  • IDE

What if there is no readline?

  • node

  • iex

  • mongodb

      brew install rlwrap
    
      rlwrap --always-readline node
      rlwrap --always-readline iex
      rlwrap --always-readline mongodb