How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+↑/↓ in Eclipse?
In Vim, you can duplicate a whole line by using the y
(yank) command to copy the current line, and then the p
command to paste it below or P
to paste it above. Here's how to do it:
Position your cursor on the line you want to duplicate.
Duplicate the line below:
- Press
yy
to copy (yank) the current line. - Press
p
to paste the copied line below the current line.
For example, if your cursor is on the line:
mathematica- Press
Line 1
After pressing yy
and then p
, you will have:
mathematica
Line 1
Line 1
Duplicate the line above:
- Press
yy
to copy (yank) the current line. - Press
P
(uppercaseP
) to paste the copied line above the current line.
For example, if your cursor is on the line:
mathematica
Line 2
After pressing yy
and then P
, you will have:
mathematica
Line 1 Line 2
You can use these commands to quickly duplicate lines in Vim. It's a bit different from the IntelliJ IDEA or Eclipse shortcuts you mentioned, but once you get used to Vim's yank and paste commands, it becomes a fast and efficient way to duplicate lines.
Comments
Post a Comment