banner

VI stands for VIsual editor that focuses on chaining different types of commands together, this tutorial plans to teach you basic vi. but all of this works in vim and vis, anything that doesn't work in basic vi implementations will be noted.

you can use the useful vi cheatsheet to refresh after reading this tutorial.

Moving your cursor

you can move around in normal mode with the hjkl keys.

h is left.

j is down.

k is up.

l is right.

Exiting VI

to save an exit simply press ZZ, to exit without saving, press ZQ.

the above may not work in simpler vi like busybox and toybox.

the alternative is :wq for write quit, :w for write, :q for quit, and :q! for force quit.

Exiting to Normal Mode

you can exit to normal mode at any time by pressing escape.

Movement Commands

w goes forward to next word

b goes backwards to last word

e goes to end of next word

% and end goes to end of line

0 and home goes to beginning of line

H goes to top of screen

M goes to middle of screen

L goes to bottom of screen

+ and enter to first character of next line

- to first character of last line

^ or _ to first non blank character

( to beginning of the current sentence

) to beginning of the next sentence

{ to beginning of the current paragraph

} to beginning of the next paragraph

[[ to beginning of current section

]] tp beginning of next section

Deletion Commands

select a character you want to delete and press x to delete it.

you can combine the d command with movement command like the following examples, delete a misplaced word with dw, or delete the garbage at the end of a line with d$.

you can delete until the end of the line with just D as well.

you can delete an entire line with dd.

Change/Replace Commands

select a character you want to replace and press r.

you can replace an entire line with R.

you can combine the c command with movement commands like so, change a word with cw.

you can use C to change until end of the line.

you can replace a character and keep typing with s.

you can replace an entire line with S.

Insertion Commands

if you press the a key you will enter insert mode after the character you had selected, you can essentially type like a normal editor in insert mode press esc to exit.

if you press i you will be in insert mode before the character you had selected.

if you press o you will be in insert mode on a new line below your cursor.

if you press A you will be in insert mode at the end of a line.

if you press I you will be in insert mode at the beginning of a line.

if you press O you will be in insert mode on a new line above your cursor.

Count Commands

you can type a number before any command to repeat it for example 10x deletes 10 characters, or 10oESC creates 10 new lines.

Undo Command

press u to undo the last command (some more basic vi's do not have undo)

Put Command

p pastes whatever is in your register usually this is your last deletion command

Yank Command

y lets you put a line in your register without deleting it.

yw yanks a word.

yy yanks a line.

works with all your basic motions.

Repeat Command

you can repeat the last command you did just by pressing .

Join Command

J joins the current line with the next line.

Screen Movement

^f moves forwards a screen.

^b moves backwards a screen.

^d moves down half a screen.

^u moves up half a screen.

^e moves down one line.

^y moves up one line.

z enter or zt snaps screen to put cursor on top.

z. or zz snaps screen to put cursor centered.

z- or zb snaps screen to put cursor on bottom.

/ searches and finds text.

Downloads

smartutor

plaintext version of this tutorial for use in VI.

usefulvi

VI Cheatsheet.