Efficient Text Editing in Vim

Alan Thomas

November 2013 / Show-Me Tech

What is Vim?

Vim

History

  • Vi editor - 1976
  • Single Unix Specification
    POSIX
  • Vi IMproved - 1991
  • (Almost adheres)

Why is it Neat?

  • Just text
  • Fingers on home row
  • Fast, fast, fast, fast, fast
  • A dialect, not shortcuts
  • Configurable
  • Extensible

Normal Mode

Normal Mode

WTF I CAN'T TYPE???!?!

Insert Mode

Insert Mode

WHEW, THIS IS BETTER

Visual Mode

Visual Mode

WAIT, I THOUGHT THIS WAS A TERMINAL???

Movement

h, j, k, l left, down, up, right
i insert
<esc> return to normal mode



Pro tip: Try these keys in Facebook, Twitter, Gmail, and many others to see vi's far-reaching influence.

Speak in Sentences

Verbs

Character Action
c change
d delete
v visually select
y yank (copy)
p put (paste)
. repeat
u undo

Nouns

Character Meaning
$ end of line
^ beginning of line
w word
s sentence
b block

Modifiers

Character Meaning
t[letter] to [letter]
i inside
5 do 5 times
[verb twice] execute on the entire line

Putting It Together

Keystrokes Translation
d$ delete to the end of the line
ciw change inside word
ci" change inside quotes
. do that again
vt< visually select to carat
yy yank current line
5p put yanked text into buffer 5 times
3dd delete current line three times
Muscle Memory

Buffers, Windows, and Tabs

:commands

Command Action
:w [file] write to [file]
:e [file] edit [file]
:sp [file] open [file] in split window
:vs [file] open [file] in vertically split window
:tabnew open a new tab
:tabf [file] open [file] in a new tab

Configuration

.vimrc

Plugins

Can it do X? Yes.

Open your terminal. Type,


$ vimtutor


Try this.

Getting Started Tips

  • Start with unconfigured Vim to gain muscle memory.
  • DO NOT touch the arrow keys.
  • Everything's weird at first. Don't tweak anything until you're comfortable with the basics.
  • Start without plugins so you can learn what comes from Vim versus what comes from the plugin.
  • Find your personal pain points while working, then configure them away.
  • Add plugins as they contribute to your workflow.
  • Avoid pre-packaged monolithic confiugrations. Try to build your own perfect fit.

Thanks!

Slides, resources, and links at:

http://barkleyus.github.io/showmetech