The vim cut and paste commands

Vim FAQ: What are the vi/vim cut and paste commands?

In vim (and vi) you can cut 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 cut and paste in vim.

The vim cut command

In short, the vim cut command is dd — the letter 'd', typed twice. This command deletes the current line, but places it in a buffer, so you can easily paste it somewhere else. You use this command while in the vim command mode.

The vim paste command

The vim paste command is the letter 'p'. When you type this 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 cut command

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

3dd

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

10dd

Once you have these lines of text in the buffer, you can again paste them somewhere else using the vim paste command (the lowercase letter 'p'), like this:

p

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