The vim copy and paste commands

Vim FAQ: What are the vim copy and paste commands?

In vim you can copy and paste content fairly easily, but being an older text editor, these commands aren't obvious. Let's take a look at how to use copy and paste in vim.

The vim copy command

In short, the vim copy command is yy -- the letter 'y', typed twice. This command copies the current line -- placing it in a vim buffer -- so you can easily paste it somewhere else. You use this copy command while in the vim command mode.

The vim paste command

The vim paste command is the letter p. When you type this paste command in vim command mode, whatever text you have saved in the buffer will be placed below the line the cursor is currently positioned on.

More advanced vim copy command

Of course you don't always want to copy and paste just one line. Many times you'll want to copy several lines, and then paste them somewhere else. To do this, you use the same vim copy command, and specify the number of lines you want to copy before the yy command. For instance, if you want to copy three lines of text, you'd use this command:

3yy

And if you want to copy 10 lines of text, you'd use this command:

10yy

Once you have these lines of text in the vim buffer, you can again paste them somewhere else using the paste command, like this:

p

For most vim copy and paste needs, those are all the commands you may ever need.