Copying an entire line in Vim is straightforward. You can follow these steps:
-
Enter Normal mode: First, ensure you are in Vim's Normal mode. If you just opened Vim or are currently in Insert mode, press
Escto return to Normal mode. -
Move to the line to copy: Use the up arrow key (
k) or down arrow key (j) to navigate to the line you want to copy. -
Copy the line: Use the
yycommand to copy the current line. Here,yrepresents yank (Vim's term for copying), andyycopies the entire current line in one step. -
Paste the line: After copying, use the
pcommand to paste the content below the current line, or usePto paste it above the current line.
Example: Suppose you are editing a text file containing the following content:
shellFirst line Second line Third line
If you want to copy "Second line", move the cursor to that line, use yy to copy it, then use p or P to paste it at your desired location.
This method is highly efficient and quick, making text editing more productive. Vim's modal editing approach is powerful; once you're familiar with these basic commands, you can quickly perform various text editing tasks.