Vi Editor Commands


vi is a modal editor that works well from a simple command line, character only terminal. The most important thing to keep in mind about vi editing is that you will be in either 1 of 2 modes, Insertion Mode, or Command Mode. Since vi works well from a character only terminal, it is essential to learn the basics of vi editing (moving the cursor, inserting text, cut/copy/paste operations), because some time with only terminal access it will be the only editor available for you to use.

Action

Key Sequence

Text Entry Mode

Enter text entry mode

i

Exit text entry mode and return to command mode.

ESC

Cursor Movement

Up one line

UpArrow or k

Down one line

DownArrow or j

Right one character

RightArrow or l

Left one character

LeftArrow or h

To start of line

Home or ^

To end of line

End or $

Back one word

b

Forward one word

w

Forward one screen full of text

PageDown or CTRL-F

Backward one screen full of text

PageUp or CTRL-B

Goto line nn

:nn<Enter> or nnG (1 means first line, $ means last line)

Deleting Text

Delete character under cursor

x

Delete word under cursor

dw

Delete current line

dd

Cut / Copy / Paste Text

Copy (yank) lines into the paste buffer

:<range>y<Enter>

Copy (yank) current line into paste buffer

Y

Insert (put) paste buffer after current line

p

Searching

Search forward from current position for string sss

/sss<Enter> (/<Enter> or n to repeat last search)

Search backward from current position for string sss

?sss<Enter> (?<Enter> or N to repeat last search)



Saving and Loading Files

Save with current name

:w<Enter>

Save file as name

:w <name><Enter>

Save file with current name and exit

:wq

Quit without saving changes

:q!

Undo and other Operations

Undo the last operation

u

Redraw the screen

CTRL-L