How to Copy and Paste From the Local Clipboard Into Vim

Nilesh Katuwal Feb 02, 2024
  1. Installing gVIM in Linux
  2. Local Clipboard into Vim in Linux
How to Copy and Paste From the Local Clipboard Into Vim

This article will learn how to copy text from the vim editor to another machine. We will be copying the content to the clipboard.

Using the yank command or registers to copy and paste within vim. However, copying to another application, such as a browser, requires additional actions.

I’ll show you how to copy text to your system clipboard using different approaches.

Installing gVIM in Linux

The Vim does not have the permission to connect your system clipboard by default; however, gaining this feature is very straightforward.

One method compiles a version of Vim that supports clipboard access, while another installs gvim.

Install gvim allows you to copy and paste to the standard terminal vim to your clipboard. In other words, it allows you to copy to a particular register that correlates to the clipboard on your system.

It’s essentially a register where you may copy items and have them immediately saved to your system clipboard. Install gVIM or vim-gtk using the following commands:

$ sudo apt-get install vim-gtk

If you need to move data from Vim to another program, use the key combination +y to copy the text and +x to clip it out of the original document.

Then tap the following three keys in order:

 " 
 + 
 x or y

In both circumstances, the cut or copied text is transferred to the clipboard and can be pasted outside vim using the standard Ctrl+V command in Linux.

Local Clipboard into Vim in Linux

The reverse procedure is also simple. The string +gP can be used to transfer text copied from the clipboard.

Let’s look at each component of the string:

  • The letter P stands for paste before the present place.
  • The letter g key moves the cursor to the end of the copied text.

The output of the gP command is as follows:

  • Place the cursor after the pasted text and paste before the current place.
  • If you don’t use g, the cursor will be positioned on the last letter of the pasted text, wasting time while you try to advance it by one character.

Related Article - Linux Vim