Using the vi Editor - Pdf 63

Using the vi Editor
Objectives
Upon completion of this module, you should be able to:
• Differentiate between the three odes of vi and identify the commands that belong
to each mode
• Start vi
• Position and move the cursor in vi
• Create text in vi
• Delete text in vi
• Copy or move text in vi
• Set vi options
• Exit the vi editor
• Perform search and replace functions within vi
Discussion – Editing system files is a powerful tool for customizing the Linux environment.
What tools would you use to edit system files?
Introduction to vi
The visual display (vi) editor is an interactive editor that is used to create and/or modify text
files.
The vi editor uses a screen display, but you cannot use the mouse to position the cursor.
All editing with the vi editor is done within a buffer. Changes can be written to the disk or
discarded.
It is important for users who are learning to become system administrators to know how to use
vi. It is the only full screen editor that can be used to edit crucial system files. This skill is also
needed in case the windowing system is not available.
 Depending on the instructor’s style, this module may be best taught by covering
the basic modes and commands of vi contained in the lecture parts of this module in a
summary fashion. The purpose of the lab for this module is to allow the students to learn vi
by using it. The lab covers in a practical fashion much of what is covered in the module, along
with some things that are not.
vi Modes
There are three modes of operation in vi:

a Append text after the cursor
A Append text at the end of the line
i Insert text before the cursor
I Insert text at the beginning of the line
o Open a new line below the cursor
O Open a new line above the cursor
Positioning Commands
The following pages list the vi editor’s editing and positioning commands, which are used to
make changes.
The vi editor is case sensitive, so use the specified case when using the editing and positioning
commands.
The Table 9-3 shows the key sequences for character movement:.
Table 9-3 : Key Sequences
Command Meaning
h, ←, or Back Space Move left one character
j or ↓ Move down one line
k or ↑ Move up one line
l,→, or Space bar Move right (forward) one character
w Move forward one word (including punctuation)
W Move forward one word (past punctuation)
b Move back one word (including punctuation)
B Move back one word (past punctuation)
e Move to end of current word
$ Move to end of line
0 (zero) or ^ Move to beginning of line
Return Move down to beginning of next line
H Move to top of screen
M Move to middle of screen
L Move to bottom of screen
Control-f Page forward one screen

r Replace character at cursor with one other character
i (Return) Break line
J Join current line and line below
xp Transpose character at cursor and character to the
right
~ Change case of letter (upper or lower) at cursor
u Undo previous command
U Undo all changes to current line
:u Undo previous last-line command
Copying and Pasting Text
To copy and paste text, use the following options:
Table 9-6 Copy and Paste Commands
Command Meaning
yy Yank a copy of line
Y Yank a copy of line
p Put yanked or deleted line below current line
P Put yanked or deleted line above current line
:1,3 co 5 Copy lines 1 through 3 and put after line 5
:4,6 m 8 Move lines 4 through 6 to line 8 (line 6 becomes line
8; line 5 becomes line 7, and line 4 becomes line 6)
Note – Both delete and yank write to a buffer. When yanking, deleting, and pasting, the
put commands insert the text differently depending on whether you are pasting a word(s)
or a line(s).
Saving and Quitting Files


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status