Vim 101

Who?

  • No previous knowledge
  • Want to learn the fundamentals concepts
  • Want to learn the basic navigation

A bit of History

  • Ed : line editor
  • Ex : Ed improved
  • Vi : Ex with visual edition
  • Vim : Vi improved
  • Neovim : ??

1970

2017

Basic modes

Normal, Insert, Visual

Normal

The mode we should spend MOST of the time

  • Run Ex commands
  • Search for text
  • Copy / Replace / Delete text

When we are in another mode, press <esc> to come back to normal

Insert

We should leave this mode as soon as possible

Because the undo command will remove all the previous command. An insertion is only one command.

Why?

Some way to insert

  • a : insert after the current character
  • i : insert before the current character
  • A : insert after the last character of the line 
  • I : insert before the first character of the line

Visual

It's sometimes faster to manually select lines 

We shouldn't use it too much though. It's not repeatable.

How to select?

Just press v to enter visual mode

Example

Update the following text to insert the missing "b" in front of "rown", then insert "The" at the beginning of the
line and finally go back to the end of line to add the missing "."

quick rown fox jumps over the lazy dog

Example

Update the following text to insert the missing "b" in front of "rown", then insert "The" at the beginning of the
line and finally go back to the end of line to add the missing "."

quick rown fox jumps over the lazy dog

Solution: 

<right><right><right><right><right>ab<esc>IThe<esc>A.<esc>

First movements

  • h : go left one line
  • j : go down one line
  • k : go up one line
  • l : go left one line

k

h

l

j

A bit more movements

  • / : Search for a text in the file
  • w : Move to the next word (                    )
  • W : Move to the next Word (Anything until            )
  • b : Move to the previous word
  • B : Move to the previous Word
  • $ : Move to end of line
  • ^ : Move to beginning of line
[a-zA-Z0-9_]+
<space>

Any movement can take a count.

For example, move to the next second word

2w

Example

Jump to the ".", then go the the beginning of "lazy", then go back to the start of the line. Finally jump to "jumps".

The quick brown fox jumps over the lazy dog.

Example

Jump to the ".", then go the the beginning of "lazy", then go back to the start of the line. Finally jump to "jumps".

The quick brown fox jumps over the lazy dog.

Solution: 

$2b^/j<enter>

First commands

  • yy : copy the current line
  • dd : delete the current line
  • p : pasting after
  • P : pasting before

Any command can take a count.

For example, to copy the 2 lines

2yy

A bit more commands

  • y + movement : copy
  • d + movement : delete

Example copy the next word

yw

Example delete until "end"

d/end

Example

Copy "The quick brown", paste it after the final ".". Then delete the word lazy.

The quick brown fox jumps over the lazy dog.

Example

Copy "The quick brown", paste it after the final ".". Then delete the word lazy.

The quick brown fox jumps over the lazy dog.

Solution: 

y/ f<enter>$p/l<enter>dw

Vim 101

By Kevin Disneur