This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Copy and Paste inside of Vim

0:55 Tools lesson by

Sometimes you just need to copy some code from one file to another. Vim allows you to do this, in a quick and efficient way.


egghead.io comment guidelines

Avatar
egghead.io

Sometimes you just need to copy some code from one file to another. Vim allows you to do this, in a quick and efficient way.

Avatar
Chris Kobrzak

Just to add my penny, if you're on OS X and would like to be able to copy something to the system clipboard, select a piece of text in Vim's visual mode and then go :w ! pbcopy.

If you switch to any other program on the Mac, it can now be pasted with Cmd+v.

In reply to egghead.io

As you can expect, VIM has the ability to copy and paste text from within the editor. Let's copy this sentence by hitting V to enter visual mode. With the whole sentence selected we can press Y on our keyboard to copy or yank the text. Then further down the file while in normal mode, we can press P to paste or put the copy text into the file. You can also do the same thing with VIM's delete command.

Back at the top of the file, pressing DD to delete the entire line behaves the same as cut would in any other editor. The text is deleted but we can still paste it back. One thing to know about VIM is that copied text does not get added to the system clipboard. If we copy this sentence again and then open up a different editor, when we try to paste we won't get the text from VIM.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?