Basics

VI has two basic modes:

Command mode

All actions around VI are taken from command mode. To enter command mode hit ESC key. As response the status bar indicates an empty state. To execute a command it should be initilized by a colon : followed by the command q (in this case quit) and finished by hitting the enter/return key CR.

E.g. :q Enter

Insert mode

In this mode all key strokes are inserted into the document, like in common GUI editors. To get from command mode to insert mode the user has to hit i. The status bar indicates this state with -- INSERT --.

Switch to command mode

ESC

Movement

Most of the movement in the document is being done from command mode. In insert mode the user can navigate via the arrow keys.

Command Description

w

Move one word forward

b

Move one word back

0

Move to start of the current line

$

Move to end of current line

ctrl + u (holding ctrl down)

Scroll up

ctrl + d (holding ctrl down)

Scroll down

Command Description

gg

Go to first line

G

Go to last line

42G

Go to line 42

Switch to edit/insert mode

Command Description

i

Insert before cursor

I

Insert before line

a

Append after cursor

A

Append after line

o

Start new line after current line

O

Start new line before current line

Delete

Command Description

x

Delete a character

dw

Delete a word

dd

Delete a line

7dd

Delete 7 lines

Copy and Paste

  1. Copy the current line with yy

  2. Move with the cursor to the wanted position

  3. Paste with p command

Command Description

yw

Copy current word, beginning from cursor position

yy

Copy current line

7yy

Copy 7 lines

p

Paste

yyp

Duplicate current line

ddkkp

Move line up

ddp

Move line down

Command Description

/foo

Search for the pattern foo forward

?foo

Search for the pattern foo backward

n

Search for next instance

N

Search for next instance in the opposite direction

/\cfoo

Search for the pattern foo forward and ignore case

/\<My Exact Search String\>

Search for the exact string My Exact Search String forward
\<: Beginning of the word
\>: End of the word.

/\<Kacper Bak\>|\<kacper bak\>

Search for the exact string Kacper Bak OR for the exact string kacper bak forward
|: OR

:%s/foo/bar/gci

Case insensitive search and replace
Change each 'foo' into 'bar'
Interactive confirmation for each step.

Working with multiple files

Command Description

:e

Open or edit file inside VI

:bd

Close file inside VI

:ls

Display all open files

:b fileName

Switch to open file

Common usage

Command Description

ctrl + n

trigger VI Autocompletion

.

Repeat last action with one key stroke

u

Undo last action

Settings

To configure VI use the keyword set.
The following command disables the line numbers e.g.: set nonumber

Command Description Example

(no)number

Enables/Disables line numbers

set number

syntax

Use syntax highlighting of a specific language

set syntax=asciidoc

Sources