How to copy and paste a line in Vim?
One of the most common task that beginners struggle to do in Vim is copying and pasting a line.
In reality though, it is very simple.
Type "yy" to copy a line, then "p" to paste it into the other place.
Now if you have some time, let's take a closer look at what's happening there. To copy a line,
- Make sure you're in the normal mode. Press
Esc
to be sure. Then copy the entire line by pressingyy
(more info:help yy
). Y stands for "yank
". Instead, you can also pressY
(shift + y) but I find the former a bit more convenient. - Paste the line by pressing
p
. That will put the yanked line right under your cursor (on the next line). You can also paste before your current line by pressing the capital letterP
. Again, to get some help you can use:help p
.
Hopefully that was helpful.
If you are serious about using Vim in your workflow, make sure to get familiar with the most popular plugins around there.
Have a productive day!