Vim Copy Text to System Clipboard

“Vim is a great text editor for any user. It provides you with a set of key combinations that will make you forget that your mouse exists.However, vim does provide quite a hill climb when you are getting started. And in this tutorial, we will attempt to make that process easier by showing you how to copy text into your system’s clipboard.”

How to Copy to System’s Clipboard

In Vim, you can copy, cut, and paste texts using the yank commands provided by the y, d, and p keys, respectively.

However, by default, vim will store the copied text into an internal register called the unnamed register. Unfortunately, this register is not supported by other applications.

This means that if you wish to paste text from vim, you will have to use the system’s clipboard.

This is what we will discuss in this tutorial.

As stated, vim does not have permission to access your system’s clipboard by default. However, you can resolve this by either compiling vim with the clipboard access ability or installing a graphical version of vim.

On Debian, install GTK Version of Vim:

$ sudo apt-get install vim-gtk

GTK-Vim allows you to have access to a special register that corresponds to the system’s clipboard. This allows you to copy and paste text from vim with the yank commands.


$ sudo yum install vim-X11


$ sudo pacman -Syu gvim

If you are on a mac, you can reconfigure the Vim Brew Formula to work with the clipboard.

Start by installing vim with Homebrew:

$ brew install vim

Once vim is installed, we can configure the formula and enable access to the system’s clipboard.

Run the command:

$ brew edit vim

The command will put you into developer mode and allow you to customize vim. In the config, locate the entry system “./configure” option.

Change the –without-x to –with-x and add the line “–with-features=huge.” Save and close the file

Next, run the command below to install the modified vim formula

$ brew install --build-from-source vim

The command should rebuild and install vim with the clipboard option.

You can check that you have the vim system’s clipboard functionality with the command:

$ vim --version | grep clipboard

If successful, you should +clipboard or +xterm_clipboard options:

Copying Text to System Clipboard

Once you have enabled the system’s clipboard access on vim, you can use the yank command, followed by a few modifications.

To copy to the system’s clipboard in Vim, start by selecting your target register using the command:


Where * refers to the system’s clipboard in mac and Windows.

Once selected, you can copy the text you wish using the y command.

Therefore, to copy a text to the system’s clipboard, run the command:


On Linux, use the command:


The commands above should allow you to copy the text into your system’s clipboard.


This tutorial explores how we can configure vim to access the system’s clipboard. We also covered the commands you can use to copy a text into the system’s clipboard in Vim.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list