Vim From Scratch

How to copy and paste a line in Vim?

> 9 months ago

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,

  1. Make sure you're in the normal mode. Press Esc to be sure. Then copy the entire line by pressing yy (more info :help yy). Y stands for "yank". Instead, you can also press Y (shift + y) but I find the former a bit more convenient.
  2. 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 letter P. 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!

Sign Up And Get A Free eBook!

If you're interested in Vim but just don't know how to start, subscribe to this newsletter. You will get notified when the course is ready and get the latest updates and articles around Vim. Also you will get a free "Vim From Scratch" eBook!