The University of Arizona.
Eller College of Management, The University of Arizona in Tucson, Arizona.
Eller IT.
Explore EllerAcademic ProgramsExecutive EducationFaculty & StaffResearch & InnovationNews & Events

Vi Editor

Movement Commands
Editing Commands
Command Line Options
Exit Commands
Alphabetical List of Keys


Movement Commands

h, j, k, l Left, down, up, right (or ¬¯­®)
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
O, $ 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
/pattern Search forward for pattern
?pattern Search backward for pattern
n, N Repeat last search in same, opposite direction
fx Search forward for character x in current line
Fx Search backward for character x in current line
tx Search forward for character before x in current line
Tx Search backward for character after x in current line
; (semicolon) Repeat previous current line search
, (comma) Repeat previous current line search in opposite direction
nG Move to line
nG Move to last line in file
:n Move to line number n
CTRL-F, CTRL-B Scroll forward, backward one screen
CTRL-D, CTRL-U Scroll down, up one-half screen
CRTL-E, CRTL-Y Show one more line at bottom, top of window
Z Return Reposition line with cursor, to top of screen
Z. Reposition line cursor, to middle of screen
Z- Reposition line with cursor, to bottom of screen
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
² Return to beginning of line containing previous mark

Editing Commands

i, a Insert text before, after cursor
I, A Insert text at beginning, end of line
o, O Open new line
r Replace with next typed character
~ Change case of character
cm Change text block defined by movement command m (e.g. cw or cL)
cc Change current line
C Change current line
R Type over characters
s Delete character and substitute text
S Delete current line and substitute text
x Delete character
X Delete character before cursor
dm Delete text block defined by movement command m (e.g. d/pattern or dG)
dd Delete current line
D Delete to end of line
p, P Put deleted text before, after cursor
²np Put text from deleted buffer number n after cursor (the last nine deletions)
ym Yank (copy) text block defined by movement command m (e.g. y]] or y})
yy, Y Yank current line
²ayy Yank current line into named buffer a
p, P Put yanked text after, before cursor
²aP Put text into buffer a before cursor
. Repeat last edit command
u, U Undo last edit, restore current line
J Join two lines
Ctrl-L Ctrl-R Redraw screen
:d Delete lines
:m Move lines
:co or :t Copy lines
:.,$d Delete from current line to end of file
:30,60m Move lines 30 to 60 after current line
:.,/pattern/co$ Copy from current line through line containing pattern to end of file

Command Line Options

vi file Invoke vi editor on file
vi file1 file2 Invoke vi editor on files squentially
view file Invoke vi editor on file in read-only mode
vi -R file Invoke vi editor on file in read-only mode
vi -r file Recover file and recnet edits after system crash
vi +file Open file at last line
vi +n file Open file directly on line number n
vi +/pattern file Open file directly at pattern
ex file Invoke ex editor on file from Unix

Exit Commands

ZZ Write (save) and quit file
:x Write (save) and quit file
:wq Write (save) and quit file
:w Write (save) file
:w! Write (save) file (overriding protection)
:30,60w newfile Write from line 30 through 60 as newfile
:30,60>> file Write from line 30 through 60 and append to file
:w%. new Write current buffer name fileas file.new
:q Quit file
:q! Quit file (discarding any changes)

Q
Quit vi and invoke ex
:e file2 Edit file2 without leaving vi
:n Edit next file
:e! Return to version of current file at time of last write (save)
:e# Edit alternate file

Alphabetical List of Keys

a Append text after cursor
A Append text at end of line
^A Unused
b Back up to beginning of word in current line
B Back to work, ignoring punctuation
^B Scroll backward one window
c Change operator
C Change to end of current line
^C Unused
d Delete operator
D Delete to end of current line
^D Scroll down half-window
e Move to end of word
E Move to end of word, ignoring punctuation
^E Show one or more line at bottom of window
fx Find next x on current line
Fx Find previous x on current line
^F Scroll Forward one window
g Unused
G Go to specified line or end of line
^G Print information about file on status line
h Left arrow cursor key
H Move cursor to Home position (top left of screen)
^H Left arrow cursor key; backspace key in insert mode
i Insert text before cursor
I Insert text at beginning of line
^I Unused in command mode; in insert mode, same as TAB
j Down arrow cursor key
J Join two line
^J Down arrow cursor key
k Up arrow cursor key
K Unused
^K Unused
l Right arrow cursor key
L Move cursor to Last position in window
^L Redraw screen (depends on terminal type)
m Mark the current cursor position in register (a-z)
M Move cursor to Middle position in window
^M Carriage Return
n Repeat the last search command
N Repeat the last search command in reverse direction
^N Down arrow cursor key
o Open line below current line
O Open line above current line
^O Unused
p Put yanked or deleted text after or below cursor
P Put yanked or deleted text before or above cursor
^P Up arrow cursor key
q Unused
Q Quit vi or invode ex
^Q Unused in command mode; in insert mode, quote next character
r Replace character at cursor with the next character type
R Replace characters
^R Redraw screen (depends on terminal type)
s Change the character under the cursor to typed character
S Change entire line
^S Unused
t Find character before next x on current line
T Find character after previous x on current line character typed
^T Unused in command mode; in insert mode, used with autoindent option set
u Undo the last change made
U Restore current line, discarding changes
^U Scroll the screen upward half-window
v Unused
V Unused
^V Unused in command mode; in insert mode, quote
w Move to beginning of next word
W Move to beginning of next word, ignoring punctuation
^W Unused in command mode; in insert mode, back up to beginning of word
x Delete character at cursor
X Delete character before cursor
^X Unused
y Yank (or copy) operator
Y Make copy of current line
^Y Show one more line at top of window
z Redraw the screen, repositioning cursor when followed by RETURN at top, . at middle, and - at bottom of screen
ZZ Exit the editor, saving changes
^Z Unused

  

 
   
Resources:
 
 
  
Eller IT Orientation Packet
Blackboard How-To Helpers
Extended University
UA Library Workshops
Multimedia Learning Lab Computer Workshops
Learning Technology Center   
 
 
  
Eller College Home   |   UA   |   Disclaimer   |   Privacy   |   Site Index

Eller College of Management   |   The University of Arizona
1130 E. Helen Street   |   P.O. Box 210108   |   Tucson, AZ 85721-0108   |   520.621.2165
  
© Copyright 2008 The University of Arizona. All rights reserved.
  

The University of Arizona : Arizona's First University.