0% found this document useful (0 votes)
9 views

Os 5 Thnew

The document summarizes the basic commands and functions of the vi text editor. It describes the two main modes: command mode, which allows administrative tasks like saving files and searching/replacing text, and insert mode, which allows inserting and editing text. It then provides instructions on starting and exiting vi, moving the cursor, adding/deleting/changing text, searching, and some advanced functions like joining lines and writing portions of the file to new files.

Uploaded by

dhruti parikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Os 5 Thnew

The document summarizes the basic commands and functions of the vi text editor. It describes the two main modes: command mode, which allows administrative tasks like saving files and searching/replacing text, and insert mode, which allows inserting and editing text. It then provides instructions on starting and exiting vi, moving the cursor, adding/deleting/changing text, searching, and some advanced functions like joining lines and writing portions of the file to new files.

Uploaded by

dhruti parikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXPERIMENT NO.

05

DATE OF PERFORMANCE: GRADE:

DATE OF ASSESSMENT: SIGNATURE OF LECTURER/ TTA:

AIM: Study of VI Editor

THEORY:
There are many ways to edit files in Unix and one of the best way is using screen-oriented
text editor vi. This editor enables you to edit lines in context with other lines in the file. Now
days you would find an improved version of vi editor which is called VIM. Here VIM
stands for Vi Improved.

OPERATION MODES
COMMAND MODE: This mode enables you to perform administrative tasks such as
saving files, executing commands, moving the cursor, cutting yanking and pasting lines or
words, and finding and replacing. In this mode, whatever you type is interpreted as a
command.
INSERT MODE: This mode enables you to insert text into the file. Everything that's typed
in this mode is interpreted as input and finally it is put in the file.

STARTING THE VI EDITOR


Command Description
vi filename Creates a new file if it already does not exist,
otherwise opens existing file.

EXAMPLE:
$vi testfile

TO EXIT VI
Command Description
:x Quit vi, writing out modified file to file
named in original invocation
:wq Quit vi, writing out modified file to file
named in original invocation
:q Quit vi even though latest changes have not
been saved for this vi call

Page 1 of 5
MOVING WITHIN A FILE
Command Description
k Moves the cursor up one line.
j Moves the cursor down one line.
h Moves the cursor to the left one character position.
l Moves the cursor to the right one character
position.
0 (zero) Move cursor to start of current line(the one with the
arrow)
$ Move cursor to end of the current line
w Move cursor to beginning of next word
b Move cursor back to beginning of preceding word
:0<return> or 1G Move cursor to first line in file
:n<return>or nG Move cursor to line n in file
:$<return>or G Move cursor to last line in file

ADDING,CHANGING,DELETING THE TEXT


Command Description
u Undo whatever you just did(a simple toggle)
nu n number steps undo(n is a any number)

INSERTING OR ADDING TEXT


Command Description
i Insert text before cursor
I Insert text at beginning of current line
a Append text after cursor
A Append text to end of current line
o Open and put text in a new line below current line
O Open and put text in a new line above current line

CHANGING THE TEXT


Command Description
r Replaces the character under the cursor
R Overwrites multiple characters beginning with the
character currently under the cursor
s Replaces the current character with the character
you type
S Deletes the line the cursor is on and replaces with

Page 2 of 5
new text

DELETING CHARACTERS
Command Description
x Deletes the character under the cursor location.
X Deletes the character before the cursor location
D Deletes from the cursor position to the end of the
current line.
dd Deletes the line the cursor is on.
ndd delete the next N lines,including the current line

COPY AND PAST COMMANDS


Command Description
yy Copy(yank) the current line
nyy copy(yank,cut) the next N lines,including
the current line
p Puts the copied text after the cursor
P Puts the yanked text before the cursor

SEARCHING THE TEXT


Command Description
/string Search forward for occurence of string in text
?string Search backward for occurence of string in text
n Move to next occurence of search string
N Move to next occurence of search string in opposite
direction

ADVANCED COMMANDS
Command Description
J Join the current line with the next one. A count joins
that many lines
:w newfile Write current contents to a new file named
newfile
:12,35w smallfile Write the contents of the line numbered 12 through
35 to a new file named smallfile

:1,10s/helo/hello/g Substitution of a text with another text within a range


of lines

Page 3 of 5
1) Create a file using vi editor Commands
output:

Page 4 of 5
Page 5 of 5

You might also like