Unix Multiple Choice Questions on “Editing Text in Vi Editor”.
1. Copying is referred to as yanking in vi editor.
a) True
b) False
Answer: a
Clarification: Copying text or characters is known as yanking in vi editor.
2. Which key is used for deleting text?
a) d
b) y
c) k
d) f
Answer: a
Clarification: ‘d’ is not a command but is used as ‘dd’ to delete entire lines. For example, to a delete a line invoke the command mode and press dd and the entire line will be deleted.
3. Which command is used for deleting a single character?
a) d
b) dd
c) x
d) w
Answer: c
Clarification: The simplest text deletion is achieved using ‘x’ command. This command deletes the character under the cursor and then the text on the right shifts towards the left to fill up space.
4. Which command is used for deleting the character on the left of the cursor?
a) x
b) X
c) dd
d) d
Answer: b
Clarification: For deleting a single character, we can use ‘X’ command. It deletes a single character but to the left of the cursor.
5. Which of the following command is used to delete a single line?
a) dd
b) x
c) X
d) d
Answer: a
Clarification: We can delete entire lines with ‘dd’ command. Just move the cursor anywhere on the line and press ‘dd’ and the entire line will be deleted.
6. Which of the following commands will be used to delete 6 lines from the current cursor location?
a) 6d
b) 6X
c) 6dd
d) 6x
Answer: c
Clarification: ‘dd’ command can be used with repeat factor to delete multiple lines at a single time. 6dd will delete the current line and 5 lines below.
7. Which command is used for putting deleted lines or part of lines at a different location?
a) p and P
b) x
c) dd
d) y
Answer: a
Clarification: Using ‘p’ and ‘P’ command we can put deleted text at a different location. For example, if we’d deleted a single character using ‘x’ then we can put that character at another location by placing the cursor at that location and pressing ‘p’ or ‘P’.
8. Both ‘p’ and ‘P’ command puts text right/left or above/below on the basis of line deleted.
a) True
b) False
Answer: a
Clarification: If we’d deleted a part of a line, then ‘p’ will put it to the right of the cursor and ‘P’ will put it to the left of the cursor. Similarly, if we’d deleted the entire line then ‘p’ will put it below the current cursor and ‘P’ will put it above the cursor.
9. To copy (yank) lines in vi editor, we use ______ command.
a) dd
b) x
c) p
d) yy
Answer: d
Clarification: To copy lines in vi editor, we can use ‘yy’ command. It works similarly as ‘dd’ command. For example, to yank 5 lines from current cursor we can use the command ‘5yy’.
10. To copy 10 lines from the current cursor location, we can use _____
a) 10y
b) 10yy
c) yy10
d) 10x
Answer: b
Clarification: Since yanking is performed by the yy command hence to copy the current line and 9 lines below we can use the command ’10yy’.
