Introducing VI Vi
Vi Commands Used To Edit Files Positioning The Cursor
Appending Commands
Deleting Text
Changing Text
Insert Mode
Copying and Pasting Text
Saving Changes and Quiting
Displaying and Hiding Line#
Searching and Replacing
Refreshing The Screen And Including Files


 

Introducing VI

Command Meaning
vi File Name Open or Create File
vi Open New File To Be Named
vi -r File Name Recover Crashed File
view File Name Open File Read-Only
vipw Edit the /etc/passwd file, setting locks and doing appropriate processing.
There are three modes of operation: Command Mode
Insert Mode
Last Line Mode

Vi Commands Used To Edit Files Positioning The Cursor

Command Meaning
h Move left one character
j Move down one line
k Move up one line
l Move right one character
w Move right one word
W Move right one word (Past Punctuation)
b Move left one word
B Move left one word (Past Punctuation)
e Move to end of current word
Return Move down one line
Backspace Move left one character
H Move to top of screen
M Move to middle of screen
L Move to bottom on screen
Control-f Scroll forward one screen
Control-d Scroll forward one-half screen
Control-b Scroll backward one-half screen
G Go to last line of file
1G Go to first line of file
21G Go to 21st line of file

Appending Commands

Command Meaning
a Append text after cursor
A Append text at line end
i Insert text before cursor
I Insert text at beginning of line
o Insert line below cursor
O Insert line above cursor

Deleting Text

Command Meaning
a Append text after cursor
A Append text at line end
i Insert text before cursor
I Insert text at beginning of line
o Insert line below cursor
O Insert line above cursor

Changing Text

Command Meaning
CW Change word (or part of word) to right of cursor
cc Change line
c Change from cursor to end of line
s Substitute string for characters from cursor forward
r Replace character at cursor with one other character
r Return Break line

Insert Mode

Command Meaning
J Join current line and line below
xp Transpose character at cursor and character to the right
~ Change case of letter (upper or lower )
u or :u Undo previous command
Undo all changes to cuurent line

Copying and Pasting Text

Command Meaning
y Yank or copy line
Y Yank or copy line
p Put yanked or deleted line below current
P Same as above

Saving Changes and Quiting

Command Meaning
:w Save changes (write buffer)
:w new file Write buffer to named file
:wq Save changes and quit Vi
:q! Quit without saving changes

Displaying and Hiding Line#

The SET command is used from last-line mode to control these options, as indicated in the table.
 
Command Meaning
:set nu Show line numbers
:set nonu Hide line numbers; setting is case sensitive
:set ic Searches should ignore case
:set noic Searches should be case sensitive
:set list Display invisible characters

Searching and Replacing

Command Meaning
/string Search for string
?string Search backward for string
n Find next occurrence of string in search direction
N Find previous occurrence of string in search direction
:%s/old/new/g Search and replace

Refreshing The Screen And Including Files

Command Meaning
Control-1 Clear (refresh) scrambled screen
:r file name Insert (read) file after cursor
:34r file name Insert file after line 34