Unix Questions and Answers – Vi Basics and Modes – 1

This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Vi Basics and Modes – 1”.

1. Which editor is used by the UNIX system to edit files?
a) vi
b) notepad
c) word
d) notepad++
View Answer

Answer: a
Explanation: It doesn’t matter what kind of work we are doing on a UNIX system, we always need an editor to edit some system files or ordinary files. For this purpose, vi editor is used in UNIX. Currently, vim (vi improved) is an improved version which is supported by LINUX systems.

2. What does the following command do?

    $ vi  file001

a) open file named file001
b) edit file named file001
c) delete a file named file001
d) open file if it exists else creates a new file
View Answer

Answer: d
Explanation: vi editor can be used for creating and editing files. In the above command, if file001 already exists, then the contents of the file will be displayed. Otherwise, an empty file named file001 will be created.
advertisement
advertisement

3. Which option is used by vi editor to open a file in read mode only?
a) -r
b) -R
c) -d
d) -f
View Answer

Answer: b
Explanation: To open an existing file in read-mode only, -R is used with the filename (as an argument). For example,

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ vi  -R  file001       // open file in read mode only

4. How many types of modes are used by vi editor?
a) 2
b) 4
c) 3
d) 1
View Answer

Answer: c
Explanation: Before working with vi editor, it is necessary to be familiar with the modes in which vi editor works. There are three different kinds of modes, namely command mode, input mode and ex mode each of which is used for a specific purpose.
advertisement

5. What is the default mode of vi editor?
a) Command mode
b) Input mode
c) Ex mode
d) Insert mode
View Answer

Answer: a
Explanation: The default mode of vi editor is command mode, where every key which is pressed is interpreted as a command to run on the text. To perform operations on text like deleting, copying, the first step you’ll have to follow is to be in the command mode so that you can run commands according to your suitability.

6. To insert text into a file, _____ mode is used.
a) Command mode
b) Input mode
c) Ex mode
d) def mode
View Answer

Answer: b
Explanation: Input mode provides us with a feature of inputting text in files. Every key pressed in this mode is recorded in the file.
advertisement

7. ex mode is used for what purpose?
a) file handling
b) substitution
c) file handling and substitution
d) Inputting text in files
View Answer

Answer: c
Explanation: ex mode performs various file handling and substitution operations like saving the file, quitting the editor, search and replace operations etc.

8. Which one of the following key is used to switch from command mode to input mode?
a) i
b) :
c) esc
d) ;
View Answer

Answer: a
Explanation: To switch from command mode to input mode press the ‘i’ key.

9. ____ key is used for switching to command mode from input mode.
a) i
b) A
c) :
d) esc
View Answer

Answer: d
Explanation: Command mode allows us to enter commands for performing operations on the text entered. To switch from the input mode to command mode press the ‘esc’ key. This operation will not be displayed on the screen but changes our mode to command mode.

10. Which of the following key is used to enter in ex-mode?
a) ESC
b) i
c) :
d) ;
View Answer

Answer: c
Explanation: To enter into ex-mode press the ‘:’ key. After that, we can press any ex-mode command followed by [Enter] to perform suitable operations.

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.