OSY 09ptttc

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Practical No.

09
Name:Prathmesh Chopade
Roll No.: 11
Batch No.: T1

X. Practical Code:
Create a file OS and type at least 30 lines in it.
i) Write command to save the file.
 Press Esc to ensure you're in command mode.
 Type :w and press Enter.

ii) Write the command to insert text at the end of line.


 Press Esc to ensure you're in command mode.
 Move the cursor to the line where you want to insert text using the arrow keys or
other navigation commands.
 Press A (uppercase 'A'). This will place the cursor at the end of the current line
in insert mode.
 Now, you can start typing the text you want to insert at the end of the line.
iii) Replace some character into beginning of second line.
 Press Esc to ensure you're in command mode.
 Move the cursor to the first character of the second line using the arrow keys or
other navigation commands.
 Press Shift + I (uppercase 'I'). This will place the cursor in insert mode at
the beginning of the current line.
 Now, you can start typing the characters you want to insert at the beginning of
the second line.

iv) Write a command to delete 10 lines at a time.


 Press Esc to ensure you're in command mode.
 Position the cursor on the first line of the block of 10 lines you want to delete.
 Type :1, 10d and then press Enter.
v) Write a command to move cursor 3 word to the right
 Press Esc to ensure you're in command mode.
 To move the cursor 3 words to the right, you can type 3w and then press Enter.
XII. Practical Related Questions:
1. What is the difference between Type o and Type O?
 o: The o command is used to open a new line below the current line. When you are
in command mode, if you press o, Vim will create a new line below the line where
your cursor is, and you'll be in insert mode on the newly created line. This is useful
when you want to insert text below the current line.
 O: The O command, on the other hand, is used to open a new line above the current
line. When you press O in command mode, Vim will create a new line above the
line where your cursor is, and you'll be in insert mode on the newly created line.
This is handy when you want to insert text above the current line.

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


Command Description
:q Quit the editor if no changes were made.
:q! Quit the editor forcibly, discarding changes.
:wq or :x Save changes and then quit the editor.
:q

:q!
:wq

:x

3. What is effect of (Type this at colon mode and observe the changes in your file)
a. set nu
b. set ic
c. set nonu
d. set noar
a. set nu: Displays line numbers on the left side of the text.
b. set ic: Enables case-insensitive search.

c. set nonu: Turns off line numbering.

d. set noar: Turns off auto-indentation and line wrap.


4. Give vi command to delete line to the left of cursor.
 Press Esc to ensure you're in command mode.
 Type D (uppercase 'D') and press Enter.

5. What is difference between yank and delete?


Operation Purpose Effect Example
Yank (y) Copies text into the Copies text without yy to yank a line.
clipboard removing it from the file.
Delete (d) Removes text Removes text from the dd to delete a line.
file.

6. What are different modes in Vi editor?


 Normal Mode: Used for navigation and issuing commands.
 Insert Mode: Used for inserting and editing text.
 Visual Mode: Used for selecting text.

7. 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:
The abbreviation command defines a text expansion for "MSBTE," but it's not meant for
manual input in the file.
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

4YY copies four lines, and P pastes them at the cursor position, effectively duplicating those
lines.

XIII. Exercise:
1. Write the significance of following.
i. $ vi temp.txt
ii. Insert multiple lines.
iii. Delete contents using commands.
i. $vi temp.txt: Opens the Vi text editor to edit "temp.txt."

ii. Insert multiple lines:


"Insert multiple lines" is useful for quickly inputting or editing multiple lines.
iii. Delete contents using commands:
Vi commands like d and dd allow efficient text deletion.

2. Create a new file and practice executing shell commands from within the
editor. Capture the results of some shell commands into the file.
To execute shell commands in Vi, use ! followed by the command. You can capture
the results by redirecting output to a file (e.g., :!ls > output.txt).

3. How to get help?


:help
$man vi:

Get help in Vi by entering command-line mode with : and using :help followed by a topic
or command. You can also access the Vi manual with man vi in the terminal for detailed
documentation.

You might also like