Pasting from the System Clipboard
In this guide you'll learn how to paste into Vim from the system clipboard using the "+P command.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

So far we've covered the basic way to copy, paste and cut commands inside of Vim. We've also discussed how we can use the visual mode to move text around and both of those are very important. However, as a developer, you probably are gonna be copying and pasting using the system clipboard, and there's a few ways of being able to do that.

I'm gonna show you, look, we're gonna create a new file here called vim package.json, and let's imagine that we're working on an Angular project. Right here, I have the package.json file for one of my Angular courses, I'm gonna copy all of this to the system clipboard. And now, if I come in and paste it, oh my goodness, look at that, so look at the way that Vim handles the copy and pasting from the clipboard.

large

This would be a horrible way of having to do this, we'd have to go through and fix the indention on every, single one of these, that is not fun.

So, there's a few way ways to get around this. First, we could type set paste, and if we do that, now if we switch into INSERT mode and hit paste, everything works, that's definitely one way of doing it. One thing that I do have to tell you, you do not want to put, set paste, inside of your vimrc file, if you do that, what it's going to do, is it's going to override many of the built-in plugin functionality kind of things and so it wouldn't really affect you right now if you did that, but if you did it later on, right after we did things such as installing some of the autocomplete plugins and things like that, it's gonna override those, and they're no longer going to work.

So, if you wanna use that paste, you really wanna do it just on a session basis, just like this. However, because it's Vim, there's a better way of doing it. So, the command I want to walk through here, is anytime that you have to paste something using the system clipboard, the command that you wanna do, and I'll type it out first before I actually do it, is going to be the " followed by a + followed by a P. If you do those three things, it's going to take the items, it's gonna automatically call set paste, and it's gonna paste the items in from the clipboard.

So, now let's see what happens. So if I am in the command mode, and I type in "+P you can see that it perfectly pastes in the items from the clipboard, and it doesn't have any of those weird indentation issues. So, that is a way that you can affectively copy and paste using the system clipboard into Vim.

large