0% found this document useful (0 votes)
15 views12 pages

Lab 4

The Operating System Laboratory Manual for the University of the Punjab outlines tasks for students to learn the VIM Editor, including familiarity with its commands and compiling C programs. Students will complete four tasks, including writing a temperature conversion program and a simple calculator program. The manual also includes grading criteria and contact information for the instructor, Dr. Ahmad Hassan Butt.

Uploaded by

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

Lab 4

The Operating System Laboratory Manual for the University of the Punjab outlines tasks for students to learn the VIM Editor, including familiarity with its commands and compiling C programs. Students will complete four tasks, including writing a temperature conversion program and a simple calculator program. The manual also includes grading criteria and contact information for the instructor, Dr. Ahmad Hassan Butt.

Uploaded by

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

OPERATING SYSTEM LABORATORY MANUAL

UNIVERSITY OF THE PUNJAB


FACULTY OF COMPUTING & INFORMATION TECHNOLOGY, LAHORE
DEPARTMENT OF COMPUTER SCIENCE

Course: Operating System Lab Date:


Course Code: CC-217-3L Max Marks: 50
Faculty/Instructor’s Name &
Dr. Ahmad Hassan Butt ([email protected])
Email:

LAB MANUAL # 4
(SPRING 2023)

Name:____________________________________ Enroll No: __________________________


OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Objective(s) :
To understand working with VIM Editor.

Lab Tasks :
Task 1 : Familiarity with Vi Editor.
Task 2: Compiling and executing a C program in VIM

Task 3 : You can convert temperature from degrees Celsius to degrees Fahrenheit by multiplying

by 9/5 and adding 32. Write a program that allows the user to enter a floating-point

number representing degrees Celsius, and then displays the corresponding degrees

Fahrenheit.

Task 4 : Write and run a program that simulates a simple calculator. It reads two integers and a

character. If the character is a +, the sum is printed; if it is a -, the difference is printed;

if it is a *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the

remainder is printed.

Lab Grading Sheet :


Max Obtained
Task Comments(if any)
Marks Marks
1. 10
2. 10
3. 10
4. 10

Total 40 Signature

Note : Attempt all tasks and get them checked by your Instructor

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
2 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Lab 04: Editor Commands

Objective(s):
To understand working with VIM Editor.

Tool(s) used:
Ubuntu, VIM Editor

VI Editor

The Vi editor is a visual editor used to create and edit text, files, documents and programs. It displays
the content of files on the screen and allows a user to add, delete or change part of text. There are three
modes available in the Vi editor, they are

1. Command mode
2. Input (or) insert mode.

Task 01 Familiarity with Vi Editor.


Starting Vi

The Vi editor is invoked by giving the following commands in LINUX prompt.

Syntax: $vi <filename> (or) $vi

This command would open a display screen with 25 lines and with tilt (~) symbol at the
start of each line. The first syntax would save the file in the filename mentioned and for
the next the filename must be mentioned at the end.

Options: vi +n <filename> - this would point at the nth line (cursor pos).

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
3 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Inserting and Replacing Commands

To move the editor from command node to edit mode, you have to press the <ESC> key. For inserting
and replacing the following commands are used.

ESC a Command

This command is used to move the edit mode and start to append after the current
character.

Syntax: <ESC>

ESC A Command

This command is also used to append the file, but this command append at the end of
current line.

Syntax: <ESC> A

ESC i Command

This command is used to insert the text before the current cursor position.

Syntax: <ESC> i

ESC I Command

This command is used to insert at the beginning of the current line.

Syntax: <ESC> I

ESC o Command

This command is insert a blank line below the current line & allow insertion of
contents.

Syntax: <ESC> o

ESC O Command

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
4 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

This command is used to insert a blank line above & allow insertion of contents.

Syntax: <ESC> O

ESC r Command

This command is to replace the particular character with the given characters.

Syntax: <ESC> rx Where x is the new character.

ESC R Command

This command is used to replace the particular text with a given text.

Syntax: <ESC> R text

<ESC> S Command

This command is used to replace a current line with group of characters.

Syntax: <ESC> S

Cursor Movement in Vi

<ESC> h

This command is used to move to the previous character typed. It is used to move to left
of the text. It can also use to move character by character (or) a number of characters.

Syntax:

● <ESC> h - to move one character to left.


● <ESC> nh - to move “n” character to left.
<ESC> l

This command is used to move to the right of the cursor (i.e.) to the next character. It can
also be used to move the cursor for a number of characters.

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
5 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Syntax:

● <ESC> l – single character to right.


● <ESC> nl – “n” characters to right.
<ESC> j

This command is used to move down a single line or a number of lines.

Syntax:

● <ESC> j – single down movement.


● <ESC> nj – “n” times down movement.
<ESC> k

This command is used to move up a single line or a number of lines.

Syntax:

● <ESC> k – single line above.


● <ESC> nk – “n” lines above.
Enter (OR) N Enter

This command will move the cursor to the starting of next lines or a group of lines
mentioned.

Syntax:

● <ESC> enter
● <ESC> n enter
<ESC> + Command

This command is used to move to the beginning of the next line.

Syntax:

● <ESC> +

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
6 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

● <ESC> n+
<ESC> - Command

This command is used to move to the beginning of the previous line.

Syntax:

● <ESC> -
● <ESC> n-
<ESC> 0

This command will bring the cursor to the beginning of the same current line.

Syntax: <ESC> 0

<ESC> $

This command will bring the cursor to the end of the current line.

Syntax: <ESC> $

<ESC> ^

This command is used to move to first character of first lines.

Syntax: <ESC> ^

<ESC> b Command

This command is used to move back to the previous word (or) a number of words.

Syntax:

● <ESC>b
● <ESC>nb
<ESC> e Command

This command is used to move towards and replace the cursor at last character of the

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
7 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

word (or) no of words.

Syntax:

● <ESC> e
● <ESC>ne
<ESC> w Command

This command is used to move forward by a single word or a group of words.

Syntax:

● <ESC> w
● <ESC> nw

Deleting The Text From Vi

<ESC> x Command

To delete a character to right of current cursor positions, this command is used.

Syntax:

● <ESC> x
● <ESC> nx
<ESC> X Command

To delete a character to left of current cursor positions, this command is used.

Syntax:

● <ESC> X
● <ESC> nX
<ESC> dw Command

This command is to delete a single word or number of words to right of current cursor
DR. AHMAD HASSAN BUTT
DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
8 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

position.

Syntax:

● <ESC> dw
● <ESC> ndw
db Command

This command is to delete a single word to the left of the current cursor position.

Syntax:

● <ESC> db
● <ESC> ndb
<ESC> dd Command

This command is used to delete the current line (or) a number of lines below the current
line.

Syntax:

● <ESC> dd
● <ESC> ndd
<ESC> d$ Command

This command is used to delete the text from current cursor position to last character of
current line.

Syntax: <ESC> d$

SAVING AND QUITING FROM Vi

<ESC> w Command

To save the given text present in the file.

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
9 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Syntax: <ESC>w

<ESC> q! Command

To quit the given text without saving.

Syntax: <ESC>:q!

<ESC> wq Command

This command quits the vi editor after saving the text in the mentioned file.

Syntax: <ESC>:wq

<ESC> x Command

This command is same as “wq” command it saves and quit.

Syntax: <ESC>:x

<ESC> q Command

This command would quit the window but it would ask for again to save the file.

Syntax: <ESC>: q

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
10 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Task 2 Compiling and executing a C program in VIM

Write and save the program in Vi:

Open a simple text editor Vi, command line code editor. Create a new File – hello.c (.c extension
is used to indicate that it’s a C program). Then write a simple HELLO WORLD program and
save it.

#include <studio.h>
void main(void){
printf(“ Hello World!\n");
}
Compile the program

Install g++ Compiler from Synaptic manager or by writing the following commands in
terminal.

sudo apt-get install gcc


gcc hello.c -o hello
If there is no syntax/semantic error in your program then the compiler will successfully generate
an executable file, otherwise fix the problem in your code.

Execute the program

To execute the program, you need to run –


./hello.out

Task 3 You can convert temperature from degrees Celsius to degrees Fahrenheit by multiplying by 9/5
and adding 32. Write a program that allows the user to enter a floating-point number representing
degrees Celsius, and then displays the corresponding degrees Fahrenheit.

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
11 | Page
OPERATING SYSTEM LABORATORY MANUAL | CC-217-3L

Task 4 Write and run a program that simulates a simple calculator. It reads two integers and a character.
If the character is a +, the sum is printed; if it is a -, the difference is printed; if it is a *, the product is
printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed.

DR. AHMAD HASSAN BUTT


DEPARTMENT OF COMPUTER SCIENCE, FCIT-PU, LAHORE
12 | Page

You might also like