How to Copy, Cut and Paste in Vim / Vi

By 

•

Updated on

•

12 min read

Vim: Copy, Cut and Paste

Vim is a terminal-based text editor that comes preinstalled on macOS and almost all Linux distributions. Unlike typical editors that use Ctrl+c and Ctrl+v, Vim has its own set of commands for copying, cutting, and pasting text.

This guide explains how to copy, cut, and paste in Vim using normal mode commands, visual mode selections, registers, and the system clipboard.

Vim Terminology

Vim uses different names for copy, cut, and paste operations:

  • Yank (y) - Copy text
  • Delete (d) - Cut text (removes it and stores it in a register)
  • Put (p) - Paste text from a register

All commands in this guide are run from normal mode. If you are in insert mode, press Esc to switch back to normal mode first.

Copying (Yanking)

To copy text, place the cursor at the desired position and press y followed by a motion command. The yanked text is stored in the default register.

Here are the most common yank commands:

  • yy - Yank the entire current line (including the newline character)
  • 3yy - Yank three lines starting from the current line
  • y$ - Yank from the cursor to the end of the line
  • y^ - Yank from the cursor to the first nonblank character of the line
  • yw - Yank from the cursor to the start of the next word
  • yiw - Yank the current word (without surrounding spaces)
  • yaw - Yank the current word (with surrounding spaces)
  • yi( - Yank the text inside parentheses
  • yi{ - Yank the text inside curly braces
  • y% - Yank to the matching bracket. Works with (), {}, and []

To duplicate the current line, use yyp: yank the line with yy, then paste it below with p.

Cutting (Deleting)

The d key cuts (deletes) text. Like yank, it takes a motion command. The deleted text is stored in the default register, so you can paste it elsewhere.

Here are the most common delete commands:

  • dd - Delete the entire current line
  • 3dd - Delete three lines starting from the current line
  • d$ or D - Delete from the cursor to the end of the line
  • d0 - Delete from the cursor to the beginning of the line
  • dw - Delete from the cursor to the start of the next word
  • diw - Delete the current word
  • x - Delete the character under the cursor

The motion commands that work with y also work with d. For example, di( deletes the text inside parentheses, and d% deletes to the matching bracket.

For more delete commands and pattern-based deletion, see How to Delete Lines in Vim .

Pasting (Putting)

To paste the contents of the default register, move the cursor to the desired location and use one of the following commands:

  • p - Paste after the cursor (or below the current line for full-line yanks)
  • P - Paste before the cursor (or above the current line for full-line yanks)

When you yank or delete a full line with yy or dd, the put command pastes the text as a new line. When you yank or delete part of a line (such as with yw), it pastes the text inline at the cursor position.

Using Visual Mode

Visual mode lets you select text visually before copying or cutting it. Vim has three visual sub-modes:

  • v - Character-wise visual mode (select individual characters)
  • V - Line-wise visual mode (select entire lines)
  • Ctrl+v - Block visual mode (select a rectangular block of text)

To copy or cut text using visual mode:

  1. Press v, V, or Ctrl+v to enter the visual mode you need.

  2. Use motion keys (h, j, k, l, or arrow keys) to extend the selection.

    Vim Copy, Cut and Paste in Visual Mode
  3. Press y to yank (copy) or d to delete (cut) the selected text.

  4. Move the cursor to the target location.

  5. Press p or P to paste.

Copy to and Paste from the System Clipboard

By default, Vim uses its own internal registers, which are separate from the system clipboard. To copy to the system clipboard in Vim, use the "+ register. To paste from the system clipboard, use the same register with the put command.

Common clipboard commands include:

  • "+y - Yank the selected text to the system clipboard
  • "+yy - Yank the current line to the system clipboard
  • "+p - Paste from the system clipboard after the cursor
  • "+P - Paste from the system clipboard before the cursor
  • "+d - Delete text and store it in the system clipboard

For example, to copy text from Vim to another application, select the text in visual mode and press "+y. You can then paste it into your browser, terminal, or editor with the normal paste shortcut for your desktop environment.

To paste text from another application into Vim, switch to normal mode and press "+p.

Checking for Clipboard Support

The "+ register can use Vim’s native clipboard support or an active clipboard provider such as OSC 52. To check whether your Vim build includes native clipboard support, run:

Terminal
vim --version | grep -ow '[+-]clipboard'
  • -o - Print only the matched text, not the whole line
  • -w - Match the whole word, so +clipboard_provider is not counted

If Vim has native clipboard support, the output is:

output
+clipboard

If the output is -clipboard, Vim has no native clipboard support. Without an active clipboard provider, typing "+yy still copies the line, but only into Vim’s default register.

Recent Vim 9.1 builds also list a +clipboard_provider feature. It allows clipboard plugins, such as the OSC 52 package described below, to provide clipboard access even in a -clipboard build. A plain grep clipboard prints both features, and it is easy to mistake one for the other.

To check whether the clipboard works in the current Vim session, run:

vi
:echo has('clipboard_working')

For native clipboard access, Vim prints 1 when the clipboard is available and 0 when it is not. A +clipboard build can return 0 over SSH or on a server without a graphical session. An active clipboard provider can provide access in those sessions.

Installing Vim with Clipboard Support

The default vim package on Ubuntu, Debian, and Fedora is built without clipboard support. Each distribution has a separate package that includes it.

On Ubuntu, Debian, and Derivatives, install vim-gtk3:

Terminal
sudo apt install vim-gtk3

Once the package is installed, the vim command starts the new build. The package also includes gVim, the graphical version of Vim. Clipboard support works on Wayland desktops too, including the default GNOME session on Ubuntu 26.04.

On Fedora, install vim-X11:

Terminal
sudo dnf install vim-X11

The package does not replace the regular vim command. To use the clipboard, start Vim with the vimx command instead.

On Arch Linux, the gvim package replaces vim and includes clipboard support:

Terminal
sudo pacman -S gvim

Recent macOS versions ship Vim with clipboard support, so you do not need to install anything.

Using the System Clipboard by Default

Typing "+ before every command gets tedious. To make the regular yank, delete, and put commands use the system clipboard, add the following line to your ~/.vimrc file:

~/.vimrcvim
set clipboard=unnamedplus

With this setting, yy copies the current line to the system clipboard, and p pastes whatever is on it. Delete commands also write to the clipboard, so dd replaces anything you copied in another application.

On macOS, use set clipboard=unnamed instead. The unnamedplus value requires X11 or Wayland support, and macOS builds do not have it.

Primary Selection

On Linux, Vim has a second selection register, "*. It holds the primary selection, the text you highlight with the mouse and paste with a middle click. The "+ register holds the regular clipboard used by Ctrl+c and Ctrl+v.

The two registers hold different text. For example, "*yy copies the current line for a middle-click paste, and the clipboard keeps its previous contents. On macOS and Windows, "* and "+ both point to the same system clipboard.

Copying over SSH

When you edit a file on a remote server, Vim runs on the server and cannot reach the clipboard on your own computer. Vim 9.1.1984 and newer include an osc52 package for this case. It sends yanked text to your terminal emulator as an OSC 52 escape sequence. The terminal then puts the text on your local clipboard.

To enable it, add the following lines to ~/.vimrc on the server:

~/.vimrcvim
packadd osc52
set clipmethod+=osc52

Once the package is loaded, "+y on the server copies text to the clipboard on your computer. Ubuntu 26.04 ships Vim 9.1.2141, which includes the package. Ubuntu 24.04 and Debian 13 ship older versions that do not.

Your terminal emulator must support OSC 52. The plugin checks this when Vim starts, but some terminals support OSC 52 without reporting it. If "+y does not copy anything, add this line above packadd osc52 to skip the check:

~/.vimrcvim
let g:osc52_force_avail = 1

If you run Vim inside tmux , also add set -g set-clipboard on to your ~/.tmux.conf file. With the default setting, tmux does not pass OSC 52 sequences from applications to your terminal.

Many terminals support copying through OSC 52 but not pasting. If "+p hangs, press Ctrl+c to cancel it and use your terminal’s paste shortcut instead.

Pasting from the Terminal

Your terminal’s own paste shortcut works even when Vim has no clipboard access. Switch to insert mode, then press Ctrl+Shift+V in most Linux terminals or Cmd+V on macOS.

Vim supports bracketed paste. The terminal marks where the pasted text starts and ends, and Vim inserts it exactly as it was copied. Some terminals, such as the Linux console, do not support bracketed paste. There, Vim treats the pasted text as typed input, and auto-indent adds extra indentation to every line.

To avoid this, turn on paste mode before pasting:

vi
:set paste

Paste mode turns off auto-indent and insert mode mappings. Paste the text, then switch it off with :set nopaste.

Select All and Copy

To select all text in Vim, press ggVG in normal mode. This command sequence moves to the first line, starts line-wise visual mode, and extends the selection to the last line.

Once the whole file is selected, you can copy it, cut it, or send it to the system clipboard:

  • ggVG - Select all text in the file
  • ggVGy - Select all and yank to Vim’s default register
  • ggVG"+y - Select all and copy to the system clipboard
  • ggVGd - Select all and delete the selected text

Use ggVG"+y when you want to copy the entire file from Vim to another application. Use ggVGy when you only need to copy all text inside Vim and paste it elsewhere in the same editing session.

For whole-file commands such as :%y and :%d, along with clipboard fallbacks, see How to Select All in Vim .

Registers

Every time you yank or delete text, Vim stores it in a register. Understanding registers gives you much more control over copy and paste operations.

The Default Register

When you run yy, dd, dw, or any other yank/delete command without specifying a register, Vim stores the text in the default register ("). The p command pastes from this register.

Named Registers

Vim provides 26 named registers (a through z). You can store text in a specific register by typing " followed by the register letter before the command.

For example, to yank the current line into register a:

vi
"ayy

To paste from register a:

vi
"ap

Named registers are useful when you need to store multiple pieces of text at the same time. You can yank one line into register a, another into register b, and paste each one independently.

Using an uppercase letter (e.g., "Ayy) appends to the register instead of overwriting it.

Viewing Register Contents

To see the contents of all registers, use the :registers command (or :reg for short):

vi
:reg

To view the contents of a specific register:

vi
:reg a

Pasting from Insert Mode

You can paste the contents of a register without leaving insert mode by pressing Ctrl+r followed by the register name. For example, Ctrl+r " pastes from the default register, and Ctrl+r a pastes from register a.

Quick Reference

For a printable quick reference, see the Vim cheatsheet .

CommandDescription
yyYank (copy) the current line
yypDuplicate the current line
3yyYank three lines
ywYank to the start of the next word
yiwYank the current word
y$Yank to the end of the line
ddDelete (cut) the current line
dwDelete to the start of the next word
DDelete to the end of the line
xDelete the character under the cursor
pPaste after the cursor
PPaste before the cursor
ggVGSelect all text in the file
ggVGySelect all and yank to the default register
ggVG"+ySelect all and copy to the system clipboard
"ayyYank the current line into register a
"apPaste from register a
"+yYank to the system clipboard
"+yyYank the current line to the system clipboard
"+pPaste from the system clipboard
:set clipboard=unnamedplusUse the system clipboard for all yanks, deletes, and puts
:regView all register contents

FAQ

What is the difference between p and P?
Lowercase p pastes after the cursor (or below the current line for full-line yanks). Uppercase P pastes before the cursor (or above the current line). The content is identical; only the position changes.

How do I copy text from Vim to another application?
Use the system clipboard register "+y to yank text, then paste with Ctrl+v in the other application. This requires native clipboard support or an active clipboard provider such as OSC 52. Check for native support with vim --version | grep -ow '[+-]clipboard'.

How do I select all text in Vim?
Press ggVG in normal mode. To copy the selection, press y. To copy the entire file to the system clipboard, press "+y after selecting all text.

Does deleting text in Vim also copy it?
Yes. Every delete command (dd, dw, x, etc.) stores the deleted text in the default register. You can paste it with p. To delete without saving to a register, use the black hole register: "_dd.

How do I paste the same text multiple times?
The register contents are not cleared after pasting. You can press p as many times as you need to paste the same text repeatedly.

Can I undo a paste?
Yes. Press u in normal mode to undo the last change, including a paste operation.

Conclusion

Vim uses yank (y), delete (d), and put (p) commands for copying, cutting, and pasting text. Named registers let you store multiple pieces of text, and the "+ register integrates with the system clipboard.

For day-to-day editing, start with yy, dd, p, and visual mode selections. When you need to move text between Vim and other applications, use the "+ register or a Vim build with clipboard support. None of it reaches disk until you save the file and exit .

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page