Unix Questions and Answers – Editing Text in Vi Editor – 2

This set of Unix Questions and Answers for Campus interviews focuses on “Editing Text in Vi Editor – 2”.

1. We can use ‘yy’ command for copy and paste operation.
a) True
b) False
View Answer

Answer: a
Explanation: We can copy lines using ‘yy’ command and paste it at another location using ‘p’ or ‘P’ command.

2. Which command is used for joining lines?
a) J
b) j
c) yy
d) jn
View Answer

Answer: a
Explanation: To join current line with the line(s) following it, we can use join (J) command. It just pulls up the following line by terminating the new line character between the current line and following line.

3. Which command will be used to join 4 lines with the current line?
a) 5J
b) 4J
c) 6J
d) 4j
View Answer

Answer: a
Explanation: Join command joins the current line with the following number of lines. For example,

advertisement
advertisement
5J    // joins current line with following four lines

4. Which of the following undo a most recent single editing change?
a) u
b) U
c) uu
d) yy
View Answer

Answer: a
Explanation: To reverse the last change you made to the buffer press the ‘u’ key. This will restore the state of the buffer by undoing the most recent action taken.

5. ___ command allows us to undo a number of changes that have been made to a single line before moving away from that line.
a) u
b) U
c) dd
d) yy
View Answer

Answer: b
Explanation: When a number of changes have to be made to a single line, vi allows us to discard all changes before you move away from the line. If the cursor has been moved to another line before invoking ‘U’, this command will not work.

6. Which command is used to redo the changes made by the undo command?
a) ctrl-l
b) ctrl-r
c) ctrl-g
d) ctrl-f
View Answer

Answer: b
Explanation: We can use the control key (ctrl-r) to redo the changes which are made by the undo command.
advertisement

7. ’10u’ command will reverse our 10 last editing actions.
a) True
b) False
View Answer

Answer: a
Explanation: We can undo multiple changes using ‘u’ command by prefixing repeat factor with command. For example,

10u        // reverses our last 10 editing actions

8. Which symbol is used for repeating the last command?
a) $
b) *
c).
d) _
View Answer

Answer: c
Explanation: Using (.) operator, we can simply repeat the last command that was used. The principle behind repeat command is, use the actual command once and then repeat it at other places with dot (.) command.
advertisement

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of Unix for Campus Interviews, 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.