You are on page 1of 4

Editing- it includes both creating a new file and modifying an existing text file

Editor- its a utility that facilitates the editing task.


Editors are classified into 2 types: line editors and screen editors
Line Editors: changes are applied to a line or group of lines. To edit a line we
must select a line or group of lines Examples: sed, ex
Screen editors: it presents a whole screen of text at a time examples: vi
The vi Editor:
When we invoke vi editor it copies the contents of the file to a memory space
known as buffer once the data have been loaded into the buffer the editor presents
a screen full of the buffer to the user for editing.
If the file does not exist an empty buffer is created.
Format:
Vi options filelist
When we exit vi, the buffer is erased, at exit time we have two options
We can quit vi without saving the file
We can save the file.
Modes:
There are two modes
Command mode
Text mode
Command mode:
When the vi editor is in command mode any key that is pressed by the user is
considered a command. As the command is entered its executed
Text mode:
When the editor is in the text mode any key that is pressed by the user is
considered text.
Default mode is command mode ie., when we invoke vi you are always in the
command mode. To exit vi we must be in command mode.
Commands
Add Commands:
Comma
nd
i
I
a
A
o
O

Function
Inserts text before the current character
Inserts text at the beginning of the current line
Appends text after the current character
Appends text at the end of the current line
Opens an empty text line for new text after the current line
Opens an empty text line for new text before the current line

Insert commands (i and I)


Lower case insert command (i) changes to the text mode, we can then enter
text
When we through entering text we return to the command mode by keying
esc.
Uppercase insert command (I) opens the beginning of the current line for
inserting text.
Append Commands (a and A)
We can append the text after the current character (a) or after the current
line (A).
New Line Commands ( o and O)
Lower case new line (o) command opens a new line after the current line
Upper case new line (O) command opens a new line above the current line
Cursor Move Commands:
Command
Horizontal
Moves
h,,backspace
1,,spacebar
0
$
Vertical
Moves
k
J
+, Return

Function
Moves the cursor one character to the left
Moves the cursor one character to the right
Moves the Cursor to the beginning of the current line
Moves the cursor to the end of the current line
Moves the cursor one line up
Moves the cursor one line down
Moves the cursor to the beginning of the previous line
Moves the cursor to the beginning of the next line.

Horizontal Move Commands:


Horizontal move commands move the cursor one character to the left or right
or to the beginning or end of the current line.
Vertical Move Commands:
Vertical move commands move the cursor up or down one line.
Deletion Commands:
Command
x
dd

Function
Deletes the Current Character
Deletes the Current Line

Delete Character(x)
Current character pointed by the cursor will be deleted
Delete Line (dd)
It Delete the current line.
Join Command(j)
Two lines can be combined using the join command
Scrolling Commands:
Unix window is 24 lines long, when we are dealing with document longer than 24
lines we need to scroll through the buffer to see the text.
Scroll down means moving down in the text toward the end of the file
Scroll up means moving the text up.
Command
Ctrl + y
Ctrl + e
Ctrl + u
Ctrl + d
Ctrl + b
Ctrl + f

Function
Scrolls up one line
Scrolls down one line
Scrolls up half a screen (12 lines)
Scrolls down half a screen (12 lines)
Scrolls up whole screen(24 lines)
Scrolls down whole screen (24 lines)

Undo Commands
Command
u
U

Function
Undoes only the last edit
Undoes all changes on the current line

Saving and Exit commands


Save work and continue (:w)
Save and continue command saves the contents of the buffer back into the
file
Save to new file (:w file name)
Writes the contents of the buffer to a new file
Save and quit (ZZ)
It saves your work and exit from vi.
Write and quit (:wq)
Its similar to save and quit
Quit (:q)
It exits vi but only if the buffer is unchanged
Quit and dont save (:q!)
It will quit the vi and dont save the changes made
Command

Function

:w
:w filename
ZZ
:wq
:q
:q!

Saves the contents of the buffer without quitting vi


Writes contents of buffer to new file and continues
Saves the contents of the buffer and exits
Saves the contents of the buffer and exits
Exits the vi( if buffer changed will not exit
Exits the vi without saving

You might also like