Return to WISEBYTES.NET Home
List of VI Commands
A page of useful vi commands for any poor non-unix person
destined to play on a unix machine without the ability to
ftp to a more "friendly" editing environment.
VI Commands
============
--------------------------------------------
Left Arrow (h) Move cursor to the left
Right Arrow (l) Move cursor to the right
Up Arrow (j) Move cursor up
Down Arror (k) Move cursor down
w Move Forward by word
W Move forward by word skipping over punctuation
b Move Backward by word
B Move backward by word skipping over punctuation
e Move Forward to the end of the word
E Move forward to the end of the word skipping over punctuation
0 Move to the First Position of current line (Start of current line)
$ Move to the Last Position of current line (End of current line)
H Move to the Top Line of screen
M Move to the Middle Line of screen
L Move to the Last Line of screen
Move Down one line
- Move Back one line
Ctrl+f Scroll Forward one screen
Ctrl+b Scroll Back one screen
Ctrl+d Scroll Down half screen
Ctrl+u Scroll Up half screen
Ctrl+g Display current line number
[n]G Move to line number [n]
G Move to last line in file
/[pattern] Search forward for [pattern]
?[pattern] Search backward for [pattern]
n Repeat last search
N Repeat last search in opposite direction
f[x] Search forward for character [x] in current line
F[x] Search backward for character [x] in current line
; Repeat previous current-line
, Repeat previous current-line search in opposite direction
% Find the next { ( or () and go to its match
Editing Commands
----------------------------
All the commands can only be give when vi is in COMMAND mode.
COMMAND mode is archieved by pressing ESC.
i Insert text Before cursor
a Insert Text After cursor
o Open new line for text Below cursor
O Open new line for text Above cursor
R Type over charcters
r Replace a character
C Change current line
:[m],[n]s/[pattern]/[replace]/ Substitute first occurrence of
pattern [pattern] (default the
last pattern) on each line with
replace b/n lines marked [m] and [n].
:[m],[n]s/[pattern]/[replace]/[flag] Substitute the pattern [pattern]
(default the last pattern)
with replace b/n lines marked [m]
and [n]. [Flag] can
either be g for global and c
for confirm, or
x Delete a character
X Delete a character Before cursor
dw Delete a word
dd Delete a line
D Delete to end of line
yy Yank current line
p Put/Paste yanked text After cursor
P Put/Paste yanked text Before cursor
Exit Commands
-----------------------
ZZ Save current file and quit
:w Save current file
:q Quit
:q! Quit without saving file
Miscellaneous Commands
---------------------------------------
. Repeat first command
u Undo last command
U Undo last command on a line
Ctrl+l Redraw screen (can us Ctrl+r)
:r [newfile] Read/retrieve contents of [newfile] into current file
m[x] Mark current position as [x]
`[x] Move cursor to position marked [x]
'x[x] Move to beginning of line containing mark [x]
:set ai Autoindent
:set noai Turn off autoindent
:set sm Show match
:set nosm Turn off showmatch
Examples
---------------
d3w Delete three words
c3c Change three lines
"[a]2dd Delete two lines and place them in named buffer [a]
"[a]p Put contents of named buffer [a] after cursor
m[b] Mark position as [b]
20 Move down 20 lines
'[b]y Yank (remember) back to mark [b]
'[c] Move to another line marked [c]
P Put yanked lines before cursor
:1,5s/hello/world/g Substitute on line 1 through 5 all patterns
hello with world
:1,$s/student/cs222/ Substitute first pattern student with cs222
on each line from first line until end of file
'a,'bs/hello/world/ Substitute first pattern hello with world on each
line from line marked a until line marked b
:f Display current file name
:w %.bak Write to new file with .bak appended to end of current filename
(eg fred.c.bak)
Lisa's Home Page |
Psychology |
Science Faculty |
Monash University
Copyright © Lisa Wise 1996 - All Rights Reserved -
Disclaimer
Last updated 11 November 1996
Maintained by lisa@wisebytes.net