---
title: "Copying, Pasting and Yanking in Vim"
url: "https://courses.osherove.com/courses/vim-hates-you/copying-pasting-and-yanking-in-vim.md"
canonical: "https://courses.osherove.com/courses/vim-hates-you/copying-pasting-and-yanking-in-vim/"
tags: []
author: "Roy Osherove"
description: "Lesson 3 of 26 in Vim Hates You (Get Somewhat productive in an hour or so), 3:30. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Copying, Pasting and Yanking in Vim

1. [Courses](https://courses.osherove.com/#courses)
2. [Vim Hates You](https://courses.osherove.com/courses/vim-hates-you/)
3. Get Somewhat productive in an hour or so

Lesson 3 of 26

Duration: 3:30 [Watch on YouTube](https://www.youtube.com/watch?v=rAGEDakYiCI)

## In this lesson

Roy explains that Vim calls copying yanking, done with y, and pastes with p after the cursor or Shift-P before it, whether the yank is a visual selection, several lines selected with Shift-V or a whole line. He shows gp, which leaves the cursor just after the pasted text, yanking a word with a motion (yank in word), copying the whole page with Shift-G, Shift-V, gg and y, and copying columns in Ctrl-V column selection mode. Registers are left for a separate video.

## Transcript

559 words

[\[00:09\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=9s) Vim has a different name for copying. It's called yanking. So if you want to copy something, use the letter Y. For example, if I go into [visual mode](https://www.youtube.com/watch?v=aaCGJCJPSjA "Vimming - Natural Selection (YouTube)") with V and I select the current these words and I press yank, then what's going to happen now is that I have this thing in memory. And how do I paste it? I use P or shift P. So P will paste after the cur just after the current cursor. So I'm going to press P. And I see that I have pasted this.

[\[00:40\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=40s) I'm going to press U for undo. But if I press shift P, it inserts this P copy before the cursor. Going to undo that, too. And this works for anything that's selected. So, for example, I'm going to select line shift V. I'm select multiple lines. Press Yank and I'm going press shift P and it pasted those lines just above my current cursor as new lines.

[\[01:12\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=72s) If you want to copy a whole line, just press Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y and this copies the current line in its entirety. Then you can press shiftp right here. You can also press GP which will actually bring the cursor just after inserting the new text. So let's say that I want to yank the current word. Motions work here too. So I'm going to say

[\[01:43\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=103s) Yank in word. This actually copied the word darkness here. I'm going to go down here. I'm going to press GP, which pastes the word darkness and moves the cursor just after it. I'm going to undo it. I'm going to say G, shiftP. I basically get the same thing. It doesn't look like it matters because I had nothing before the cursor in this current line, but basically it will paste the word just before the cursor versus just after and move the cursor to the end of the pasted text, which in this case kind of looks the same.

[\[02:21\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=141s) So that's yanking and pasting. That's what you're going to do most of the time. For example, if you want to copy the whole page, you can press shift G to go to the bottom of the page, shift V to select the whole line and then GG to go up to the beginning of the page and press Y. And now you've pasted the whole page. You've you've copied the whole page. Now you can paste it anywhere with shift P or P just like this. And we've copied the whole thing.

[\[02:52\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=172s) You can of course go to into column selection mode with Ctrl +V. Select all these columns here and press Y. And now they're all pasted. They're all copied. If I go here and I press P, I should have the columns pasted right here. Let's see. I'm going to add more lines here just so we can see what it looks like. And you can see all the columns here.

[\[03:22\]](https://www.youtube.com/watch?v=rAGEDakYiCI&t=202s) So that's it for copying and pasting. We still haven't talked about registers, which is a really cool concept. I'm going to cover that in a separate video.

## Related

### Also linked in this lesson

#### YouTube

- [Vimming - Natural Selection](https://www.youtube.com/watch?v=aaCGJCJPSjA)

[Previous lesson Vim file open save, load, moving, changing and selecting text](https://courses.osherove.com/courses/vim-hates-you/vim-file-open-save-load-moving-changing-and-selecting-text/) [Next lesson Syntax Highlighting and Numbering in .vimrc file](https://courses.osherove.com/courses/vim-hates-you/syntax-highlighting-and-numbering-in-vimrc-file/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
