Main Menu

Vim Copy, Cut & Paste: Complete Clipboard Guide 📋

Here's the short version, because that's probably what you came for. In Vim, you copy a line with yy, copy three lines with 3yy, cut a line with dd, paste after the cursor with p, and paste before it with P. To send text to your system clipboard, use "+y, then paste it anywhere outside Vim like normal.

That's the whole game in one breath. The rest of this guide fills in the gaps — registers, visual mode, clipboard troubleshooting, and the stuff that actually trips people up over SSH. By the end, you'll not only know the basic commands, but also how to leverage Vim's registers, visual selections, and clipboard integration across Linux, macOS, and Windows.

Action Command What it does
Copy line yy Yanks the current line
Copy 3 lines 3yy Yanks 3 lines from cursor down
Cut line dd Deletes line, stores it for pasting
Paste after p Pastes below/after the cursor
Paste before P Pastes above/before the cursor
Copy to clipboard "+y Yanks into the system clipboard
Quick Picks card titled Vim Copy/Paste Cheat listing key Vim copy, cut, and paste commands.

One thing worth saying upfront: nearly all of this works in classic vi too, but the system clipboard parts ("+y, "*y) depend on your Vim build. More on that later. For a deeper comparison of Vim with other editors, check out Vi vs Vim and Vim editor vs Nano editor.

Understanding Vim Modes for Copying and Pasting

If you've never used Vim before, this part confuses everyone at first. Vim has modes. You can't just highlight with the mouse and hit Ctrl+C — well, you sort of can, but that's not the Vim way.

Normal mode

This is where you land when you open a file. No typing text here instead, every key is a command. yy, dd, p all live here. Press Esc any time to get back to it.

Visual mode

Visual mode is how you select text manually. Three flavors: v for character-by-character, V for whole lines, and Ctrl+v for block selection. Once text is highlighted, y copies it and d cuts it.

Insert mode

Press i and you're typing actual text. This is also where terminal paste shortcuts come into play when you're bringing in text from outside Vim. Hit Esc to leave.

Vim modes state diagram showing Normal, Insert, and Visual with i, v/V/Ctrl+v, and Esc arrows

Basic Vim Copy, Cut, and Paste Commands

Now the core commands. These are the foundation of how to copy text in Vim, but mastering them in different modes and integrating with system clipboards makes them much more powerful.

How to copy a line in Vim

Put your cursor anywhere on a line and press yy. Done — the line is in the unnamed register, ready to paste. "Yank" is just Vim's word for copy.

How to copy multiple lines in Vim

Prefix yy with a number. So 5yy copies five lines starting from the cursor. Want to copy from the cursor to the end of the file? Use yG. From the cursor to the top? ygg.

How to copy a word or part of a line

This is where text objects shine. yiw yanks the word under the cursor (inner word, no surrounding spaces). yaw grabs the word plus a trailing space. And y$ copies from the cursor to the end of the line. For a whole paragraph, yap does the trick. y% copies all text between matching brackets — useful for functions and arrays.

How to cut text in Vim

Here's the thing most beginners miss: deleting in Vim is cutting. When you press dd, that line isn't gone forever — it's sitting in a register waiting for you to paste it. So dd cuts a line, d$ cuts to end of line, and daw deletes a word. All of them store the text. For more on this, see our guide on how to delete lines in Vim.

How to paste in Vim

Lowercase p pastes after the cursor (or below, for linewise yanks). Uppercase P pastes before. That's it. The distinction matters more than you'd think once you start copying lines around.

Stylised Vim terminal showing a yanked line with yy and the same line pasted below with p.

How to Copy and Paste in Visual Mode in Vim

Visual mode feels more natural to newcomers because it's closer to highlighting with a mouse. You see exactly what you're grabbing. It's especially useful when copying multi-line code snippets or making block edits — a common scenario for developers and sysadmins.

Characterwise selection with v

Press v, then move with arrow keys or h j k l. The text between your start point and cursor gets highlighted. Hit y to copy or d to cut. Great for grabbing half a line.

Linewise selection with V

Capital V selects entire lines. Move up or down to extend the selection across multiple lines, then y. This is the visual-mode equivalent of 3yy but you can see what you're catching.

Blockwise selection with Ctrl+v

Ctrl+v is the underrated one. It selects a rectangular block — columns of text. Perfect for editing aligned data or commenting out a column of code. Select your block, then y to copy it.

How to replace selected text safely

Here's a classic gotcha. You copy something, then you visually select text you want to replace and paste over it with p. Surprise — your copied text is now gone, overwritten by whatever you just deleted.

The fix is "_dP. Select the text, then run that. The "_d deletes into the black hole register (so it doesn't touch your clipboard), and P pastes your original copy. Your yank survives. This is used constantly by experienced Vim users.

Stylised Vim visual mode graphic showing Ctrl+v block selection across multiple lines in a column

Vim Registers Explained

Registers are just labeled clipboards. Vim has a bunch of them, and once you understand the main ones, copy/paste stops feeling random. Run :registers any time to see what's stored where. Vim stores copied and deleted text in these temporary storage locations, and by default, commands like y or d use the unnamed register.

The unnamed register

The default. Every yank and delete lands here (the " register) unless you say otherwise. That's why p pastes your last yank or delete.

Named registers

You've got a through z to stash text manually. Prefix a yank with the register name: "ayy copies a line into register a, and "ap pastes it back. Use uppercase like "Ayy to append to that register instead of overwriting.

Numbered registers

Register 0 always holds your most recent yank, separate from deletes. So even if you delete a bunch of stuff, "0p still pastes the last thing you actually copied. Registers 1 through 9 hold your recent deletes, like a delete history.

The black hole register

The "_ register is a void. Anything sent there disappears and doesn't disturb your other registers. That's exactly why "_dP works for safe replacing.

Useful register examples

  • "ayy — copy current line into register a
  • "ap — paste from register a
  • "0p — paste your last yank, ignoring deletes
  • :registers — view all register contents
Infographic showing five Vim register types with labels, purposes, and example commands.

How to Copy from Vim to the System Clipboard

This is the question that brings most people here. You copied something in Vim, switched to your browser, hit paste — and got nothing. The unnamed register isn't your system clipboard. You need the clipboard registers.

Using "+y and "+p

The + register is your system clipboard. So "+yy copies the current line into the clipboard, and you can paste it anywhere with Ctrl+V. Going the other way, "+p pastes your system clipboard into Vim.

Using "*y and "*p on Linux

On Linux, * is the primary selection — the middle-click paste buffer — while + is the standard clipboard (Ctrl+C/Ctrl+V). On Windows and macOS, + and * are basically the same thing. So "*y copies to the primary selection on Linux.

How to set clipboard=unnamedplus

Typing "+ before every yank gets old fast. Add this to your ~/.vimrc:

set clipboard=unnamedplus

Now every plain yy goes straight to the system clipboard. To copy the entire file to the clipboard in one shot, use :%y+ — clean and quick.

Clipboard Setup and Troubleshooting on Linux, macOS, and Windows

If "+y does nothing, your Vim probably wasn't built with clipboard support. This is the single most common copy-to-clipboard failure, and it's fixable.

How to check clipboard support

Run this in your terminal:

vim --version | grep clipboard

You want to see +clipboard or +xterm_clipboard. If you see -clipboard (with a minus), your build doesn't support it.

Stylised terminal illustration showing Vim clipboard check with +clipboard and +xterm_clipboard highlighted

What to install if clipboard support is missing

The tiny Vim that ships by default on many distros lacks clipboard. Install a fuller build:

OS / Distro Package to install
Ubuntu / Debian vim-gtk3 (or gvim)
Fedora vim-X11
Arch Linux gvim (clipboard-enabled build)
macOS MacVim, or Vim via Homebrew

On Linux you'll also want xclip or xsel installed so Vim has a tool to talk to X11. And a heads-up: Neovim handles clipboard differently — it shells out to an external tool (xclip, xsel, wl-copy, or pbcopy), so if those aren't installed, Neovim clipboard won't work either.

Terminal Vim vs GUI Vim

gVim and MacVim almost always have clipboard support baked in, since they're GUI apps. Terminal Vim is where you hit the missing-clipboard wall most often. If you're stuck with terminal Vim and can't rebuild, the GUI version is a quick workaround.

SSH, tmux, and WSL limitations

This is the messy part. When you're in Vim over an SSH session, the "system clipboard" is the remote machine's clipboard — which usually has no display attached. So "+y often does nothing useful over SSH. tmux complicates it further with its own copy buffer. For WSL, older versions had no native clipboard bridge, though newer WSL plus a clipboard tool like win32yank handles it. The honest answer: remote clipboard is finicky, and sometimes the most reliable move is selecting text with your terminal's own copy shortcut.

Decision tree for troubleshooting Vim clipboard support and SSH copy behavior

How to Copy and Paste Between Files and Buffers in Vim

One of Vim's strengths is the ability to work with multiple files and buffers efficiently. Moving text between files is a daily task for sysadmins and developers.

Copying between buffers

Open multiple files with vim file1 file2. Yank text in one buffer, switch with :bnext or :bprev, and paste with p. The unnamed register carries across buffers in the same Vim session, so no extra steps needed.

Copying between files with registers

For separate Vim sessions, the system clipboard is your bridge: "+yy in one, "+p in the other. Or use named registers within a session — "ayy in file one, switch files, "ap in file two. This method ensures you do not overwrite your clipboard contents when performing complex multi-file operations. Handy when copying a config block somewhere specific.

Copying all text from a file

To select everything: ggVG (go to top, linewise visual, jump to bottom). To copy the whole file to the system clipboard, chain it: ggVG"+y. Or skip selection entirely with :%y+. For more on selection, see our guide on how to select all in Vim.

How to Paste in Insert Mode Without Breaking Indentation

Ever paste code into Vim and watch it cascade into a staircase of runaway indentation? That's Vim's auto-indent reacting to each pasted newline. Annoying, but easy to stop.

Using terminal paste shortcuts

When pasting from outside, you're often using your terminal's paste, not Vim's. On Linux terminals it's usually Ctrl+Shift+V. On macOS Terminal and iTerm it's Cmd+V. Windows Terminal uses Ctrl+Shift+V or right-click, and PuTTY pastes with a right-click or Shift+Insert.

Using :set paste and :set nopaste

Before pasting external text, run :set paste. This disables auto-indent so your text lands exactly as copied. After you're done, turn it back off with :set nopaste. You can bind a toggle key with :set pastetoggle=<F2> so you're not typing the command every time.

When paste mode is still necessary

Modern terminals with bracketed paste mode often detect pastes automatically and skip the indentation mess — so you may not need :set paste at all anymore. But on older setups or over SSH, it's still your reliable fix. If indentation still gets mangled, try :set mouse= to rule out mouse interference.

Common Vim Copy/Paste Examples

Real tasks, real commands. These are the ones used most often in daily work.

Copy a line and paste it below

yyp. Yank the line, paste it right below. Instant line duplication — great for copying a config entry or a function signature.

Copy 5 lines in Vim

5yy then p where you want them. Or duplicate a 10-line block downward with 10yy followed by p.

Copy a word in Vim

yiw copies the word under the cursor. Move somewhere else and p drops it in. For replacing a word with one you copied, viwp works (but remember the overwrite caveat — use viw"_dP to keep your yank).

Move text instead of copying it

Cut and paste. dd then p moves a line. To move 10 lines down a few rows: 10dd, navigate, p. Since delete stores the text, moving is just cut-then-paste.

Copy code from a remote server

On a remote box without clipboard support, the simplest reliable path is selecting the text with your local terminal's mouse/copy, or using :%y+ if clipboard forwarding works. When wrangling big config files, our notes on how to search for text in Vim pair nicely with copy workflows.

Real-Life Use Cases

Here are a few practical scenarios where mastering copy and paste in Vim is especially useful:

  • Developers: Copying a function from one file to another without leaving Vim.
  • Sysadmins: Extracting log snippets across multiple configuration files.
  • Writers: Reorganizing text sections or moving paragraphs efficiently.

Additionally, using visual mode selection combined with named registers or system clipboard integration can save time and prevent errors when working with long scripts or large documents.

Troubleshooting Common Vim Copy and Paste Problems

Why "+y is not working

Almost always missing clipboard support. Run vim --version | grep clipboard. See a minus sign? Install vim-gtk3 (Debian/Ubuntu) or vim-X11 (Fedora), and make sure xclip is present. Over SSH, this is expected behavior — fall back to terminal copy.

Why pasted text is indented incorrectly

Auto-indent fighting your paste. Use :set paste first, paste, then :set nopaste. Modern terminals with bracketed paste usually handle this for you.

Why your copied text got overwritten

You pasted over a visual selection, which dumped the deleted text into your unnamed register. Either grab it back with "0p (register 0 keeps your last yank), or avoid the problem entirely using "_dP next time.

How to undo and redo after pasting

Pasted in the wrong spot? u undoes it, Ctrl+r redoes. For the full picture, read our guide on undo and redo in Vim.

Accidentally overwriting a register

Use named registers ("a to "z) to save important yanks or deletes.

Copying between remote sessions

Use system clipboard commands ("+y and "+p) when working in GUI Vim or with vim-gtk on Linux. When that fails, terminal copy shortcuts are the reliable fallback.

Quick Reference Cheat Sheet

Essential copy commands

  • yy — copy line · 3yy — copy 3 lines
  • yiw — copy word · y$ — copy to end of line
  • yG — copy to end of file · ggVGy — copy whole file
  • y% — copy inside brackets

Essential cut commands

  • dd — cut line · 5dd — cut 5 lines
  • d$ — cut to end of line · daw — cut a word
  • x — cut character

Clipboard commands

  • "+y — copy to clipboard · "+p — paste from clipboard
  • :%y+ — copy whole file to clipboard · ggVG"+y — same via visual
  • set clipboard=unnamedplus — make clipboard the default

Register commands

  • "ayy / "ap — yank/paste named register a
  • "0p — paste last yank · "_dP — safe replace
  • :registers — list all registers

Want a printable version? Download the Vim cheat sheet. For the broader command set, see our roundup of essential Vim commands, and when you're ready to wrap up an edit, here's how to save changes in Vim.

Downloadable Vim quick map card with copy, cut, clipboard, and register commands.

Conclusion

Mastering copy and paste in Vim is more than knowing a few commands — it's about understanding modes, using registers effectively, integrating with system clipboards, and handling multi-file workflows efficiently. For everyday work you really only need yy, dd, p, and P. Add "+y the moment you need to copy out to your browser or another app, and lean on registers once you start juggling multiple snippets.

The clipboard stuff trips people up most, so bookmark the troubleshooting section. And if you live on remote servers, accept that SSH clipboard is just quirky — keep your terminal's own copy shortcut handy as a fallback. Practice the core commands for a week and they'll be muscle memory. Also, for Linux users optimizing Vim workflows, consider a Linux VPS for a dedicated development environment.

People are also reading:

Category: Tutorials Linux

Write Comment