Introduction to Vim

An Introduction to Vim

Alex LaFroscia      @alexlafroscia

A Quick History

About Vim

  • Created in 1991
  • Runs in a terminal window
  • Liked for speed, customization

Why Use Vim?

  • Very portable configuration
  • Extremely fast editing
  • Awesome plugin community

Things to Know

  • Available in a terminal window
  • No mouse!

Learning Curve

Title Text

Getting to Know Vim

3 Modes

  • Normal Mode
  • Insert Mode
  • Visual Mode

Normal Mode

  • Movement allowed
  • Execute Vim commands
  • Move quickly around the file
  • Other modes return to here

Visual Mode

  • Movement allowed
  • Select text
  • Cut/Copy (yank)
  • Paste 

Insert Mode

  • Movement (sort of) allowed
  • Most similar to editors that you're familiar with

File Commands

Manipulating the File

Movement

// Basic motion

h : move right
l : move left
j : move down
k : move up


// Jumping

w  : beginning of next word
e  : end of next word
b  : beginning of previous word
ge : end of previous word
%  : jump to matching symbol


// Moving Faster

2h : move 2 characters right
4w : move to the front of the 4th word
  • Arrow keys work, but don't use them
  • By default, move one "step" at a time
  • Can be combined with numbers to repeat movements

Operations

// Basic Ops

x : delete
r : replace (single character)
c : replace selection


// Undo

u     : undo one step
ctl-r : repo one step


// Moving Text Around

d : cut
y : copy (yank)
p : paste after (similar to a)
P : paste before (similar to i)


// Other

/ : search in file
  • The basic commands of Vim
  • Text manipulation

Transitioning Between Modes

// Insert Mode

i : insert "under" cursor
a : insert "after" cursor

I : insert at beginning of line
A : insert at end of line

o : insert on next line (below)
O : insert on previous line (above)


// Visual Mode

v     : regular selection
V     : line selection
opt-v : block selection


// Leaving a Mode

esc : back to normal
  • Vim gives lots of options for transitioning between modes
  • Picking the right command is important 

Vim Commands

Controlling the Editor

Basic Commands

// Quitting Vim

:q   : quit
:qa  : quit all
:qa! : force quit all


// Save a File

:w   : save
:wq  : save and quit


// Other stuff

:help __command_name__
  • Vim commands usually start with a colon
  • Toggle features on and off

Vim Features

What sets Vim apart?

Panes

// Movement

h : move right
l : move left
j : move down
k : move up


// Jumping

w  : beginning of next word
e  : end of next word
b  : beginning of previous word
ge : end of previous word
  • Allows you to have multiple files open at once
  • Can split horizontally or vertically
Made with Slides.com