---
title: Vim Copy Paste: Yank, Put and the System Clipboard | Relic
description: Vim copy paste, explained: yank and put, registers like "0, the "+ system clipboard, fixing -clipboard builds, :set paste, Neovim providers, SSH and tmux.
canonical: https://relic.space/blog/how-to-copy-and-paste-in-vim
source: https://relic.space/llms.txt
---
[Developer cheat sheets](https://relic.space/blog/topics/dev-reference)

# How to copy and paste in Vim

In Vim, **y** copies and **p**pastes. Vim calls them yank and put. Those keys use Vim’s own storage, so to reach the clipboard every other app uses, you add `"+` in front: `"+yy` to copy a line out, `"+p` to paste one in.

[JGJordan Gibbs](https://relic.space/authors/jordan-gibbs) October 20, 2026 9 min read

## How do you copy and paste in Vim?

Press **Esc** for normal mode. Type **yy** to copy the current line, or press **v**, move to select text, and press **y**. Move the cursor and press **p** to paste after it, or **P** to paste before it. For the system clipboard, type `"+` first, as in `"+y` and `"+p`.

normal mode, the ones you use daily

yy      copy the current line (3yy copies three)
yw      copy to the start of the next word
yiw     copy the word under the cursor, wherever the cursor sits in it
y$      copy to the end of the line
yap     copy the paragraph and the blank line after it
ggyG    copy the whole file

p       paste after the cursor (below the line, for whole lines)
P       paste before the cursor (above the line, for whole lines)
gp      like p, but leave the cursor just after the pasted text
]p      like p, but match the indent of the current line

dd      cut the line (every delete is also a copy in Vim)

**y** takes any motion, so if you know how to move somewhere, you know how to copy to there. `y}` copies to the end of the paragraph, `yt,` copies up to the next comma, and `yi"` copies whatever sits inside a pair of double quotes. One small surprise: in Vim, **Y** copies the whole line, the same as yy. In Neovim it copies to the end of the line, because [Neovim maps Y to y$ by default](https://neovim.io/doc/user/change/).

## Selecting with visual mode

When the motion is hard to name, select by eye. There are three visual modes, and they all end the same way: press **y** to copy or **d** to cut.

|            | Key    | What it selects                      | Good for                                                   |
| ---------- | ------ | ------------------------------------ | ---------------------------------------------------------- |
| Characters | v      | from the cursor to wherever you move | part of a line, or a span across lines                     |
| Lines      | V      | whole lines                          | functions, config blocks, anything you will paste as lines |
| Block      | Ctrl+v | a rectangle                          | one column out of aligned text or a table                  |

The way you copied decides how **p** behaves. Text yanked with V or yy is linewise, so p drops it on a new line below. Text yanked with v or yw is characterwise, so p puts it right after the cursor, mid-line. When a paste lands in the wrong place, this is usually why.

On Windows, Ctrl+V may never reach Vim. Windows Terminal binds it to paste by default, and gVim on Windows often maps it to paste as well. Use Ctrl+Q instead. It starts block selection the same way, which [Vim’s Windows help](https://vimhelp.org/gui%5Fw32.txt.html#CTRL-V-alternative) suggests for exactly this case.

## Registers: why p sometimes pastes the wrong thing

The classic Vim moment goes like this. You yank a line, delete another line to make room, press p, and get the deleted line back. Nothing is broken. Every yank and every delete writes to the **unnamed register**, and p reads from it, so the delete replaced your yank.

Your yank is still there. [Vim’s register docs](https://vimhelp.org/change.txt.html#registers) say register 0 holds the text from the most recent yank, and deletes leave it alone. So the fix is `"0p`. The ones you’ll actually use:

* `""` is the unnamed register, the one plain y, d and p use.
* `"0` holds your last yank. Deletes don’t touch it.
* `"1` to `"9` hold your last nine deletes of a line or more, newest first. Smaller deletes, like a word, go to `"-` instead.
* `"a` to `"z` are yours to name. `"ayy` saves a line in a, `"ap` pastes it. Use the capital letter, `"Ayy`, to add to a register without replacing it.
* `"_` is the black hole. `"_dd` deletes a line without touching any register.
* `"+` and `"*` are the system clipboard, covered next.

Type `:reg` to see what each register holds right now. A register name goes before the command, so the same pattern works everywhere: `"ayiw`, `"+yap`, `"0P`.

## How do you copy from Vim to the system clipboard?

Use the plus register. `"+yy` copies a line to the clipboard, a visual selection followed by `"+y` copies the selection, and `"+p` pastes whatever you copied in your browser. From the command line, `:%y+` copies the whole file. In insert mode, Ctrl+R then **+** pastes the clipboard without leaving insert mode.

There are two clipboard registers because Linux has two clipboards. `"+` is the normal one you paste with Ctrl+V. `"*` is the primary selection, the text you last highlighted, which you paste with a middle-click. Only Linux tells the two apart. The Vim docs say they are the same register on Windows, and a Mac behaves the same way. If you only learn one, learn `"+`.

### First, check that your Vim can see the clipboard

Do this before you change any settings.

shell

vim --version | grep clipboard

A `+clipboard` in the output means you’re set. A `-clipboard`means this build of Vim can’t reach the system clipboard at all, and `"+y` quietly falls back to the unnamed register. From inside Vim, `:echo has('clipboard')` gives the same answer as a 1 or a 0.

The two Vims on one Windows 11 machine show how much this varies. We checked on 20 October 2026\. The Vim 9.1 that comes with Git Bash reported `+clipboard`, and `has('clipboard_working')` came back 1\. The Vim 9.1 package in Ubuntu 24.04, running under WSL on the same machine, reported `-clipboard`.

### Why clipboard support is missing, and the fix

On Linux, terminal Vim reaches the clipboard through the graphical session (X11, or Wayland in newer builds). The plain `vim` package on Debian and Ubuntu is built without those graphical libraries. The fix is the bigger package, which still runs in the terminal as `vim`:

Debian and Ubuntu

sudo apt install vim-gtk3

Other distributions have a similar package, usually the one that also ships gVim. Installing xclip on its own does not change anything for Vim, whatever some guides say. Vim talks to the display directly, and it’s Neovim that leans on tools like xclip.

Wayland is the newer wrinkle. Vim got native Wayland clipboard support in patch 9.1.1485, according to [its version notes](https://vimhelp.org/version9.txt.html). Distributions with an older 9.1, like Ubuntu 24.04’s 9.1.0016, predate it. If you can’t get a clipboard build, pipe through a clipboard tool. This works in any Vim:

Vim command line

:'<,'>w !wl-copy
:r !wl-paste

The first line copies the selected lines. Select them with V, then type **:** and Vim fills in the `'<,'>` for you. The second line pastes the clipboard below the current line. On X11, swap in `xclip -selection clipboard` to copy and `xclip -selection clipboard -o` to paste. On a Mac use `pbcopy` and `pbpaste`, and in WSL, `clip.exe` copies. This always sends whole lines, so for a few words the clipboard register is easier.

### Making y and p use the clipboard every time

If typing `"+` gets old, the `clipboard` option makes plain y and p use the system clipboard. Put this in your vimrc:

\~/.vimrc

set clipboard^=unnamed,unnamedplus

Note the `^=`. The Vim docs warn against appending with `+=`, because on X11 the default value ends in an `exclude:` pattern and anything added after it is read as part of that pattern. Several popular guides use `+=` anyway, and on Linux that can leave the setting doing nothing. Per [the option’s docs](https://vimhelp.org/options.txt.html#clipboard-unnamedplus), with both values set, yanks go to both clipboards on Linux.

We think plenty of people are better off without it. With this on, every **dd** and every **x** overwrites what you copied in your browser a minute ago. Yanking with `"+` on purpose keeps the two apart. And if you do turn it on, a clipboard manager like [Relic](https://relic.space/)keeps the earlier copies, so a stray delete doesn’t cost you the URL you meant to paste.

## Neovim: the clipboard goes through a helper tool

Neovim has no built-in connection to the clipboard. It finds a helper program and runs it to copy and paste. Once it finds one, `"+` and `"*` work exactly as in Vim. The [docs list the tools it looks for](https://neovim.io/doc/user/provider/#clipboard-tool), in order:

* macOS: `pbcopy` and `pbpaste`, which are always there.
* Linux on Wayland: `wl-copy` and `wl-paste`, from the wl-clipboard package.
* Linux on X11: `xsel` or `xclip`.
* Windows: `win32yank` first, with `clip` and PowerShell further down the list.
* Inside tmux, or a terminal that supports it: tmux buffers, then OSC 52.

Run `:checkhealth vim.provider` to see which one Neovim picked, or why it found none. On a Linux box where `"+y`does nothing, the answer is almost always “install wl-clipboard or xclip”. To use the clipboard for every yank, the Lua version of the setting is:

init.lua

vim.opt.clipboard = "unnamedplus"

The Neovim docs also give a ready-made `g:clipboard` block for WSL that copies with `clip.exe` and pastes through PowerShell. Use that one if detection picks the wrong tool there.

## How do you paste into Vim without the indentation going wrong?

You copy a tidy block of code from a browser, press Ctrl+Shift+V in insert mode, and every line lands further right than the last. The terminal is typing the text into Vim one key at a time. Vim can’t tell that from you typing, so its auto-indent adds a level on top of the indentation already in the text.

From the most reliable fix to the oldest:

* **Paste from the register.** In normal mode, `"+p` inserts the text as one piece, so auto-indent never runs. In insert mode, Ctrl+R Ctrl+O then **+** inserts it literally, with no auto-indent. You need a clipboard build for both.
* **Let bracketed paste handle it.** Vim has supported it since patch 8.0.0210\. The terminal marks where pasted text starts and ends, and [Vim then inserts it literally](https://vimhelp.org/term.txt.html#xterm-bracketed-paste). Vim switches it on by itself for terminals that identify as xterm, which covers most terminal apps. Inside tmux or screen it often stays off, and Vim’s terminal docs give a few lines of vimrc to force it there.
* **Fall back to paste mode.** Run `:set paste`, paste, then `:set nopaste`. [The paste option](https://vimhelp.org/options.txt.html)turns off auto-indent, mappings and abbreviations while it’s on, which is why you have to remember to turn it back off.

Neovim users can skip the last one. Neovim’s [deprecated list](https://neovim.io/doc/user/deprecated/) calls the paste option obsolete, because Neovim handles pasted text on its own. It also dropped `pastetoggle`, so old vimrc lines that set it don’t carry over.

## Copying out of Vim over SSH

When Vim runs on a server, `"+y`can’t reach the clipboard on your laptop. The server usually has no display, so it has no clipboard of its own either. The fix is **OSC 52**, an escape code that Vim prints and your local terminal turns into a copy on your machine. Your terminal has to support it. Windows Terminal does, and iTerm2 does once you allow apps to access the clipboard in its settings.

**Neovim** does this on its own. Its [OSC 52 provider](https://neovim.io/doc/user/provider/#clipboard-osc52) switches on when it finds no other clipboard tool, which is the normal state of a server, but only while the `clipboard` option is empty. If you set `unnamedplus` in a shared config, or tmux gets in the way of the detection, force it:

init.lua

vim.g.clipboard = "osc52"

**Vim** caught up in version 9.2, which ships an [optional osc52 package](https://vimhelp.org/usr%5F05.txt.html#package-osc52). It needs a Vim built with the clipboard provider feature, which arrived in patch 9.1.1857\. Turn it on in your vimrc:

\~/.vimrc

packadd osc52
set clipmethod+=osc52

The package’s own help warns about pasting. Some terminals let a program copy through OSC 52 but not paste. On those, a `"+p` just waits until you press Ctrl+C, and setting `g:osc52_disable_paste` to true stops the wait. tmux can confuse its detection too. On an older Vim, the vim-oscyank plugin does the same job. Copying out of a remote shell without any editor is covered in [copy and paste in the terminal](https://relic.space/blog/copy-and-paste-in-the-terminal).

## How do you copy in tmux?

tmux has its own copy and paste, called copy mode. Press the prefix (Ctrl+B by default) then **\[** to enter it, and the prefix then **\]** to paste what you copied. Inside copy mode, the keys depend on the `mode-keys` option. The [tmux manual](https://man7.org/linux/man-pages/man1/tmux.1.html) says it defaults to emacs keys, unless your `VISUAL` or `EDITOR`variable contains “vi”. Most Vim users want this:

\~/.tmux.conf

setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
set -g set-clipboard on

The two bind lines are there because tmux’s vi keys aren’t quite Vim’s. Out of the box, **Space** starts a selection, **Enter** copies it, and **v** switches to a rectangle. With the lines above, v and y work the way your fingers expect.

The last line is about the clipboard. tmux’s `set-clipboard` option defaults to `external`in tmux 3.4, which we confirmed on Ubuntu 24.04\. With that default, a copy you make in copy mode already goes to your terminal’s clipboard through OSC 52, as long as tmux knows your terminal supports it. Setting it to `on`also lets programs inside tmux, like Neovim or Vim with the osc52 package, send their copies out. If you also want tmux’s copies piped to `pbcopy` or `wl-copy`, the [terminal guide](https://relic.space/blog/copy-and-paste-in-the-terminal) has that config.

## Questions that come up next

How do I copy the whole file in Vim?+

Type ggyG in normal mode. gg jumps to the first line and yG yanks everything down to the last one. To send the whole file to the system clipboard instead, run :%y+ on the command line. The % means every line and the + names the clipboard register.

Why doesn't Ctrl+C copy in Vim?+

In a terminal, Ctrl+C is the interrupt key. Inside Vim it cancels a half-typed command or drops you out of insert mode. Vim copies with y, a habit it kept from vi. If you select text with the mouse and it lands on your clipboard, your terminal did that, and Vim never saw it.

How do I paste a register into Vim's command line or a search?+

Press Ctrl+R and then the register name. Ctrl+R " pastes the last yank or delete, Ctrl+R 0 pastes the last yank, and Ctrl+R + pastes the system clipboard. It works the same way in insert mode.

For the other half of daily Vim use, the patterns in `/` and `:s` follow most of the rules in our [regex cheat sheet](https://relic.space/blog/regex-cheat-sheet), with Vim’s own escaping on top. And if the two clipboards on Linux are new to you, [what the clipboard is](https://relic.space/blog/what-is-the-clipboard) explains where copied text actually lives.

## Sources

* [Vim reference manual: registers (change.txt)](https://vimhelp.org/change.txt.html#registers), Vim help
* [Vim reference manual: options, including clipboard and paste](https://vimhelp.org/options.txt.html), Vim help
* [Neovim providers: clipboard integration](https://neovim.io/doc/user/provider/), Neovim
* [tmux(1) manual page](https://man7.org/linux/man-pages/man1/tmux.1.html), man7.org

JG

Written by

[Jordan Gibbs](https://relic.space/authors/jordan-gibbs)Founder, Relic

Jordan Gibbs is the founder of Relic, an end-to-end encrypted, permanent, searchable memory for everything you copy. He writes widely about AI, agents, and practical tooling on Medium, where he is read by tens of thousands, and builds privacy-first software. Here he covers how everyday tools like the clipboard actually work, and how to use them without handing your data to someone else.

[Medium](https://medium.com/@jordan%5Fgibbs)[GitHub](https://github.com/jordan-gibbs)[LinkedIn](https://www.linkedin.com/in/jordan--gibbs/)

Part of

[Developer cheat sheets](https://relic.space/blog/topics/dev-reference)
* [Regex cheat sheet· pillar](https://relic.space/blog/regex-cheat-sheet)
* [How to copy to the clipboard from the command line](https://relic.space/blog/copy-to-clipboard-from-the-command-line)
* [What AI crawlers fetch from a small open-source site: 31 days of logs](https://relic.space/blog/ai-crawlers-on-a-small-site)
* [JSONPath examples](https://relic.space/blog/jsonpath-examples)
* [jq cheat sheet](https://relic.space/blog/jq-cheat-sheet)
* [wget vs curl: what is the difference?](https://relic.space/blog/wget-vs-curl)
* [Subnet cheat sheet](https://relic.space/blog/subnet-cheat-sheet)
* [Port numbers list](https://relic.space/blog/port-numbers-list)
* [Ed25519 vs RSA](https://relic.space/blog/ed25519-vs-rsa)
* [TOML vs YAML](https://relic.space/blog/toml-vs-yaml)

Keep reading

[Pillar·10 minRegex cheat sheetThe regex pieces you actually reach for, character classes through lookarounds, with the flavor differences that bite you and a handful of patterns worth saving.Read ](https://relic.space/blog/regex-cheat-sheet)[8 minHow to copy to the clipboard from the command linePipe any command into the clipboard on Mac, Linux, Windows and WSL. The commands for each, plus the newline and encoding problems that break pasted text.Read ](https://relic.space/blog/copy-to-clipboard-from-the-command-line)[9 minWhat AI crawlers fetch from a small open-source site: 31 days of logsWe checked every request that claimed to be GPTBot, ClaudeBot, PerplexityBot and the rest against the operators' published IP lists. Then we looked at what the real ones read. The data is downloadable.Read ](https://relic.space/blog/ai-crawlers-on-a-small-site)

developerhow-toreference
