Short Reference Guide to vi Commands

Short Reference Guide to vi Commands
Moving Around

h, j, k, l - moves one space or line left, down, up, right.

^D, ^F, ^U, ^B - moves 1/2 or a full screen at a time.

0 - moves to the beginning of a line

$ - moves to the end of a line.

H, M, L - moves to top, middle or bottom of screen

G - moves to end of file

1G - moves to first line of file.

nG - moves to line n in file.

w - moves forward a word

b - moves backward a word

e - moves to end of current word

‘ (single-quote) - moves back to “previous” location.

(, ) - move to the beginning (end) of the current sentence.

{ , } - move to the beginning (end) of the current paragraph.

Getting rid of Things

d - deletes the object

dd - a line

dw - a word

d$ = D - from here to end of current line

d0 - from here to beginning of current line

x - one character

dG - delete from here to end of file.

Adding and Changing Text

i - enter insert mode to left of current cursor position

I - insert at beginning of current line

a - enter insert mode to right of current cursor position

A - insert at end of current line

r - replace a single character

R - enter overstrike mode.

c

- change the object, and then enter insert mode

u - undo the last text addition or deletion

:i,js/ //g - substitute replacement for all occurrences of pattern in the line range i, j

y - yank the object (make a copy and put it into the deleted text buffer).

Y - yank an entire line (or lines)

Saving Changes, Quitting, reading and writing files

ZZ - save the current file and exit.

:w - write using current file name

:w - write using new name.

:w! - write, even though a file exists with that name.

:q - quit without saving

:q! - really quit.

:wq - write and then quit

:x - exit while saving changes

:r - read the named file into the buffer at the current cursor position.

Marking lines and Finding Patterns

mx - mark the current position, and name it x (legal names are a-z, inclusive)

/ - search foreward in the text for the given pattern.

? - search backward in the text for the given pattern.

n - find the next instance of the pattern.

N - find the next instance of the pattern backwards.

Miscellaneous Commands

^Z - suspend execution of vi and return to the shell (see the jobs and fg commands to see how to return to vi)

^V - prefix command to allow you to insert control characters into text.

~ (tilde) - change the case of the current character.

n>> - move indentation n lines right shiftwidth spaces

n< < - move indentation n lines left shiftwidth spaces

> - shifts the text object (lines only) shiftwidth spaces

< - shifts the text object (lines only) shiftwidth spaces

. (period) - repeat the last insert or deletion command.

Hints and Tips

xp - swap two letters ddp - swap two lines

dwwp - swap two words dwbp - swap two words backwards.

There are 26 named buffers defined in vi; these buffers can be used to hold text in cut and paste operations and to hold boilerplate for memos, letters, etc.

“xy yanks the text object into the named buffer.

Example: “ay9 will yank the current line and the next 9 lines into the buffer “a.

“xp - will put the contents of the buffer “x at the current cursor position.

  • Both comments and trackbacks are currently closed.
  • Trackback URI: http://www.frankl.info/wordpress/uncategorized/short-reference-guide-to-vi-commands/trackback/
  • Comments RSS 2.0

Comments are closed.