LFCS Exam: Using Commands for Multiple Rows in vi Editor

Using Commands for Multiple Rows in vi Editor

Question

In the vi editor, how can commands such as moving the cursor or copying lines into the buffer be issued multiple times or applied to multiple rows?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

B

The answer to the question is B. By specifying the number right in front of a command such as 4l or 2yj.

In vi editor, there are several commands that can be used to move the cursor, copy or delete text. These commands can be repeated multiple times or applied to multiple rows by specifying a number before the command.

For example, to move the cursor 4 characters to the right, you can use the command '4l'. Similarly, to copy two lines, you can use the command '2yj' which copies the current line and the line below it.

These commands can be used to repeat any action multiple times or apply it to multiple rows. For instance, if you want to delete 3 lines, you can use the command '3dd' which deletes the current line and the two lines below it.

Alternatively, you can also use the '.' command to repeat the previous command. For example, if you want to delete 3 lines, you can use the command 'dd' to delete the current line and then use the '.' command to repeat the delete command for the next two lines.

Therefore, using a number before a command or the '.' command can help you repeat any command multiple times or apply it to multiple rows in the vi editor.