LFCS Exam: Insert Deleted Content in vi - Linux Foundation Certified System Administrator

Insert Deleted Content in vi

Question

Immediately after deleting 3 lines of text in vi and moving the cursor to a different line, which single character command will insert the deleted content below the current line?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

C

The correct answer is C. p (lowercase).

Explanation:

In vi editor, the command to delete a line of text is "dd". So, if we want to delete 3 lines of text, we can type "3dd". After deleting the text, if we want to insert it below the current line, we can use the "p" command. The "p" command stands for "put" and it will insert the deleted text below the current line.

For example, let's say we have the following text in vi:

scss
Line 1 Line 2 Line 3 Line 4

If we want to delete lines 2, 3, and 4, we can type "3dd" while the cursor is on line 2. The text will now look like this:

scss
Line 1

The deleted text is now in the buffer, ready to be put back in the file. If we want to insert the deleted text below line 1, we can move the cursor to line 1 and type "p". The text will now look like this:

scss
Line 1 Line 2 Line 3 Line 4

Option A (i) is the command to enter insert mode, which is not relevant to this scenario.

Option B (P) is the command to put the deleted text above the current line.

Option D (U) is the command to undo the last action, which would undo the deletion of the text.

Option E (u) is the command to undo the last action for a single line, which would also undo the deletion of the text.