0% found this document useful (0 votes)
33 views10 pages

Osy 9

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)
33 views10 pages

Osy 9

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/ 10

DEPARTMENT OF INFORMATION TECHNOLOGY

Subject: Client Side Scripting Subject Code:


Semester: 5 Course: Operating System
Laboratory No: Name of Teacher: Sunil Sir
Name of Student: Neel Gadekar Roll ID:22202B0040

Experiment No: 9

Aim
Use vi editor and perform all editor commands

Theory: -

Sr.
Command Description
No.

Creates a new file if it already does not exist, otherwise opens an


1 vi filename
existing file.
2 vi -R filename Opens an existing file in the read-only mode.

3 view filename Opens an existing file in the read-only mode.

Following is an example to create a new file testl if it already does not exist in the
current working directory -
The above command will generate the following output
$vi testl

"test I" [New File]


You will notice a tilde (~) on each line following the cursor. A tilde represents an
unused line. If a line does not begin with a tilde and appears to be blank, there is a
space, tab, newline, or some other non-viewable character present.
Operation Modes

While working with the vi editor, we usually come across the following two modes -

Command mode - This mode enables you to perform administrative tasks such as
saving the files, executing the commands, moving the cursor, cutting (yanking) and
pasting the lines or words, as well as 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
Ill

this mode is interpreted as input and placed in the file.


vi always starts in the command mode. To enter text, you must be in the insert mode
for which simply type i. To come out of the insert mode, press the Esc key, which will
take you back to the command mode.

Moving within a File


To move around within a file without affecting your text, you must be in the command
mode (press Esc twice).
Sr. No. Command Description

1 k Moves the cursor up one line

2 j Moves the cursor down one line

3 h Moves the cursor to the left one character position

4 I Moves the cursor to the right one character position

Control Commands:-

Editing Files

To edit the file, you need to be in the insert mode. There are many ways to enter the
insert mode from the command mode -

Sr.No. Command Description

1 i Inserts text before the current cursor location

2 I Inserts text at the beginning of the current line

3 a Inserts text after the current cursor location

4 A Inserts text at the end of the current line

5 0 Creates a new line for text entry below the cursor location

6 0 Creates a new line for text entry above the cursor location

Page movement Description:-

Sr.No. Command Description

1 CTRL+d- Move forward 1/2 screen

2 CTRL+f- Move forward one full screen

3 CTRL+u- Move backward 1/2 screen

4 CTRL+b Move backward one full screen

5 CTRL+e Moves screen up one line

6 CTRL+y- Moves screen down one line


7 CTRL+I Redraws screen
Deleting Characters

Here is a list of important commands, which can be used to delete characters and lines in
an open file -

Sr.No. Command Description

1 X Deletes the character under the cursor location

2 X Deletes the character before the cursor location

3 Dw Deletes from the current cursor location to the next word

4 di\ Deletes from the current cursor position to the beginning of the line

5 d$ Deletes from the current cursor position to the end of the line

6 D Deletes from the cursor position to the end of the current line
7 dd Deletes the line the cursor is on

Change Commands

You also have the capability to change characters, words, or lines in vi without
deleting them.

Sr. No. Command Description

1 cc Removes the contents of the line, leaving you in insert mode.

2 cw Changes the word the cursor is on from the cursor to the


lowercase w end of the word.

3 r Replaces the character under the cursor. vi returns to the command


mode after the replacement is entered.

4 R Overwrites multiple characters beginning with the character currently


under the cursor. You must use Esc to stop the overwriting.

5 s Replaces the current character with the character you type. Afterward,
you are left in the insert mode.

6 S Deletes the line the cursor is on and replaces it with the new text. After
the new text is entered, vi remains in the insert mode.

Copy and Paste Commands

You can copy lines or words from one place and then you can paste them at another
place using the following commands -
Sr. No. Command Description

1 yy Copies the current line.

2 yw- Copies the current word from the character the lowercase w cursor is on,
until the end of the word.

3 p Puts the copied text after the cursor

4 P Puts the yanked text before the cursor.

Ex mode command

Press Esc key and then(:) colon to enter ex-mode commands. A colon is displayed at the
left hand comer of the last line on your screen.

Command Action
:w Saves file and remains in editing mode
:x Saves file and quits editing mode
:wq Save and quit
:q Quits vi when no changes are made
:q! Quits vi cancelling the changes
:sh Escape to Unix shell

Advanced Commands

There are some advanced commands that simplify day-to-day editing and allow for more
efficient use of vi -

Word and Character Searching

The vi editor has two kinds of searches: string and character. For a string
search, the / and ? commands are used. When you start these commands, the command
just typed will be shown on the last line of the screen, where you type the particular string
to look for.
These two commands differ only in the direction where the search takes place -
• The / command searches forwards (downwards) in the file.
• The? command searches backwards (upwards) in the file.
The n and N commands repeat the previous search command in the same or the opposite
direction, respectively. Some characters have special meanings. These characters must be
preceded by a backslash (\) to be included as part of the search expression.

Sr. No. Character escription


1 A Searches at the beginning of the line (Use at the beginning of a search
expression).

2 I Matches a single character.


Operating System IF5I-B

3 * Matches zero or more of the previous character.

4 $ End of the line (Use at the end of the search expression).

Running Commands

The vi has the capability to run commands from within the editor. To run a
command, you only need to go to the command mode and type:! command.
For example, if you want to check whether a file exists before you try to
save your file with that filename, you can type :! ls and you will see the output
of ls on the screen. You can press any key (or the command's escape sequence) to
return to your vi session.

Replacing Text

The substitution command (:s/) enables you to quickly replace words or groups of
words within your files. Following is the syntax to replace text -

:s/search/replace/g

The g stands for globally. The result of this command is that all occurrences on
the cursor's line are changed.

Practical Related Questions


Note: Below given are few sample questions for reference. Teacher
must design more such questions so as to ensure the achievement of
identified CO.

1. What is the difference between Type o and Type O?


Ans
Type o (lowercase o):
In the context of the ls command or certain other file manipulation commands, -o is a flag or option.
Example: ls -o will list files with details but without showing group information.
In general, lowercase o is commonly used for shorter, more specific options or flags in many Linux
commands.
Type O (uppercase O):
Uppercase O is used for different options or arguments in many Linux commands.
For example, in the tar command, -O (uppercase) will extract files to standard output: tar -xvf
archive.tar -O.

22202B0040 Neel Gadekar


Operating System IF5I-B

The distinction between lowercase and uppercase options is important in Linux, as the two often
perform completely different actions.

2.State the three ways quit the vi-editor.


Ans Different ways to quit the vi-editior are:
 Quit without saving
 Quit and save changes
 Save and quit (shortcut)

3.What is effect of (Type this at colon mode and observe the changes in your file)
Ans
a) set nu
b) set ic
c) set nonu
d) set noai

set nu
 This command enables line numbering in the file. Every line in the file
will be prefixed with its corresponding line number.
b) set ic
 This command enables case-insensitive search. After this is set,
searches in vi will ignore case, so abc, ABC, and aBc will all match.
c) set nonu
 This command disables line numbering. If line numbers were enabled
using set nu, this will turn them off.
d) set noai
 This command disables auto-indentation. With auto-indentation off, vi
will no longer automatically indent new lines to align with the previous
lines, and you'll need to manually indent lines if desired.

6.Give vi command to delete line to the left of cursor.


Ans. The d0 command in vi deletes everything to the left of the cursor on the current line. It removes
all characters from the cursor position to the start of the line.

7.What is difference between yank and delete?


Ans. Yank (y):
 Yank copies text without removing it from the document.
 It places the copied text in the unnamed register (clipboard), allowing
you to paste it later using p or P.
Delete (d):
 Delete removes text from the document and also places it in the
unnamed register, allowing it to be pasted later.
 Unlike yank, delete modifies the document by removing the selected text.

22202B0040 Neel Gadekar


Operating System IF5I-B

8.What are different modes in Vi editor?


Ans. The different modes in vi editor are :
Normal Mode,insert mode , visual mode , command line mode.

9.Observe the output of following commands:


i) at colon mode
:abbr MSBTE Maharashtra State Board Of Technical
Education Now in the beginning of your file type MSBTE
and press space bar Write down the output

ii) Go to beginning of your file


press 4YY Then move to
end of your file and press
'P'
Write the purpose of the command

Conclusion: -
We learned how to use vi editor and also about the different modes present in vi editor .

22202B0040 Neel Gadekar

You might also like