Information Technology College of HoChiMinh city
Faculty of Information Technology
Course: Fundamentals of Linux OS
Unit 5
Using vi editor
Lecturer: Võ Tấn Dũng
/>
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.
VÕ TẤN DŨNG
vi Modes
There are three modes of operation in vi:
• Command mode
• Entry mode
• Last-line mode
When you open a file with vi, you are in command mode. In
this mode, you can enter positioning and editing
commands to perform functions. While in command mode
you can do advanced editing commands by typing a colon
(:), which places you at the bottom line of the screen. This
is called last-line mode. However, all commands are
initiated from command mode.
VÕ TẤN DŨNG
vi Modes (cont.)
• You must be in entry mode to enter text. To enter text, you
must type a vi insert command such as i, o, or a. This takes
vi out of command mode and puts it into entry mode. In this
mode, text will not be interpreted as editing commands.
When you finish entering text in your file, press the Escape
key to return to command mode.
VÕ TẤN DŨNG
Invoking vi
Command Format
vi [option(s)] [filename]
view [filename]
Example
• To create a new file, invoke vi with a new file name by typing
$ vi filename
VÕ TẤN DŨNG
Input Commands
• To append or insert text, use the following options:
VÕ TẤN DŨNG
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.
VÕ TẤN DŨNG
Positioning Commands (cont.)
This table shows the key sequences for character movement:.
VÕ TẤN DŨNG
Editing Commands: Deleting Text
VÕ TẤN DŨNG
Editing Commands:
Undoing, Repeating, and Changing Text Commands
VÕ TẤN DŨNG
Editing Commands:
Copying and Pasting Text
VÕ TẤN DŨNG
Editing Commands:
Saving and Quitting Files
VÕ TẤN DŨNG
Advanced Editing Options
The vi editor includes options for customizing your edit sessions, such as:
• Displaying line numbers
• Displaying invisible characters such as tab and end-of-line characters
The set command is used from last-line mode to control these options.
VÕ TẤN DŨNG
Advanced Editing Options (cont.)
To find a line or to search and replace and do advanced
editing, use the following options:
VÕ TẤN DŨNG
Advanced Editing Options (cont.)
VÕ TẤN DŨNG
Creating and Saving a File
VÕ TẤN DŨNG
END OF UNIT 5
• remember to do your homework
(see />
VÕ TẤN DŨNG