Linux Administration
medium
Questão de Linux Administration #019e3987
Enunciado da Questão
Linux Administration
#vi
#yank
#yy
#buffer
#copy-line
Médio
In the vi editor, which of the following commands will copy the current line into the vi buffer?
A
c
B
cc
C
1c
D
yy
Correta
E
1y
Explicação Oficial / Explicações da Comunidade
The yy command (or Y) in vi yanks (copies) the entire current line into the vi buffer. This is the standard command for copying a line in vi's normal mode.
How it Works
In vi, the y (yank) operator copies text into a buffer without deleting it. When followed by a motion, it yanks from the cursor to the target of the motion. The yy command is a special case that yanks the entire current line, equivalent to y_ or Y (if Y is not remapped). The buffer contents can then be pasted with p (after cursor) or P (before cursor).
Why the Correct Value is Right
yy: This is the correct command. It yanks the current line into the buffer. The number prefix1is optional, so1yyalso works, butyyis the standard form.
Why the Incorrect Values are Wrong
c: Theccommand is the change operator. It deletes text and enters insert mode. It does not copy.cc: Thecccommand changes (deletes and inserts) the current line. It does not copy.1c: This is a change command with a count prefix. It changes one line (the current line) by deleting it and entering insert mode. It does not copy.1y: While1ywould yank one line (the current line) if followed by a motion,1yalone is incomplete. In vi,1ywithout a motion is not a valid command; it would wait for a motion. The correct form isyyor1yy.