vi Movement Commands

h,j,k,l

Left, Down, Up, Right (<, v, ^, >)

Text

w,W,b,B

Forward, backward by word

e, E

End of word

), (

Beginning of next, previous sentence

}, {

Beginning of next, previous paragraph

]], [[

Beginning of next, previous section

Lines

0, $

First, last position of current line

^

First character of current line (ignore spaces)

+, -

First character of next, previous line

n|

Column n of current line

H

Top line of screen

M

Middle line of screen

L

Last line of screen

nH

n (number) of lines after top line

nL

n (number) of lines before last line

Screens

Ctrl-F  Ctrl-B

Scroll forward, backward one screen

Ctrl-D  Ctrl-U

Scroll down, up one-half screen

Ctrl-E  Ctrl-Y

Show one more line at bottom, top of window

z [Return]

Reposition line with cursor: to top of screen

z.

Reposition line with cursor: to middle of screen

z-

Reposition line with cursor: to bottom of screen

Ctrl-L  Ctrl-R

Redraw screen (without scrolling)

Searches

/pattern

Search forward for pattern

?pattern

Search backward for pattern

n, N

Repeat last search in same, opposite direction

/, ?

Repeat previous search forward, backward

Line number

Ctrl-G

Displays filename, current line no., total no. of lines

nG

Move to line number n

G

Move to last line in file

:n

Move to line number n

Marking position

mx

Mark current position as x

`x

Move cursor to x

``

Return to previous mark or context

'x

Move to beginning of line containing mark x

               

Abbreviations

:map x sequence

Define keystroke x as a command sequence

:map! x sequence

Define x as command sequence for insert mode

:unmap x

Disable the map x

:unmap! x

Disable insert mode map x

:ababbr  phrase

Abbreviate phrase as abbr; when abbr is typed in insert mode, it expands to full words or phrases

:unab abbr

Disable abbreviation

 

vi Editing Commands

Insert

i, a

Insert text before, after cursor

I, A

Insert text at beginning, end of line

o, O

Open new line for text below, above cursor

Change

r

Change single character

cw

Change word

cc

Change current line

C

Changes the rest of the line (same as c$)

R

Type over characters

s

Delete character and substitute text

S

Delete current line and substitute text

Delete, move

x

Delete character at the cursor

X

Delete character before cursor

dw

Delete word

dd

Delete current line

D

Delete to end of line

p, P

Put deleted text after, before cursor

"n p

Retrieves the nth last delete of a complete line or block of lines

Yank

yw

Yank (copy) word

yy

Yank current line

"ayy

Yank current line into named buffer a

p, P

Put yanked text after, before cursor

"aP

Put text from buffer a  before cursor

Other commands

.

Repeat last edit command

u, U

Undo last edit; restore current line

J

Join two lines

~

Changes letter at the cursor to the opposite case.

 

vi Exit Commands

ZZ

Write (save) and quit file

:x

Write (save) and quit file

:wq

Write (save) and quit file

:w

Writes the edit buffer contents to the original file

:w!

Write (save) file (overriding protection)

:30,60w newfile

Write from line 30 through line 60 as newfile

:30,60w>> file

Write from line 30 through line 60 and append to file

:w %.new

Write current buffer named file as file.new

:q

Quit file

:q!

Quit file (overriding protection)

:e file2

Edit file2 without leaving vi

:n

Edit next file

:e!

Re-edits the current file and discards all changes.

:r file

Reads the file into the editing buffer by adding new lines below the current line

:r !command

Runs command and places its output into the file by adding new lines below the current cursor position.

%

Current filename

 

http://beesharp.com/vi.pdf