Introduction
When you install vim, a usual requirement as with all text editors is the ability to copy to/from system clipboard so you can lets say, copy something into your vim session from firefox or vice versa, however copy pasting in terminal editors is not as straight forward as with GUI editors. In vim if you want to copy something into an auxilary space (anticipating it would be used later, so you can paste from this auxilary space) is achieved by registers.
The register that represents system clipboard is +
register. Anything
that you copy into this register is available in system clipboard.
How to use registers to copy/paste
To copy a text into a register, select it in visual mode and press
"<register_name>y
to yank the contents into the given register. And to
paste the contents of a particular register at current position, use
"<register_name>p
.
To use system clipboard, you just have to substitute “+” for register name in the above commands.
clipboard support
But the +
register wont work unless you have clipboard support with
your vim installation. By default there is no clipboard support in vim.
To check if your vim installation has clipboard support use:
|
|
or inside of vim, you can run the command:
|
|
If the output is 0, your installation doesnt have clipboard support.
Compiling vim
Now there are 2 solutions to this problem:
- Either install gvim:
- Or compile vim from sources with clipboard support
Let’s see how each of them can be done.
Install gvim
To install gvim
run:
On Debian:
|
|
On Fedora
|
|
To compile vim with clipboard support
Below are the simple steps:
Step 1: Grab the sources
Clone the repository:
|
|
Step 2: Install dependencies
Install the required libraries and tools to build vim, for example gcc, x11 etc. Note that you only need them to compile vim and you are free to delete them once you are done.
On Debian:
|
|
On Fedora:
|
|
Also, you need to remove the existing installation(if any).
On Debian
|
|
On Fedora
|
|
Step 3: Configure and Compile
Configure vim with features of your choice
|
|
Then compile and install with:
|
|
Conclusion
In this article we learned how can we compile vim with clipboard support, you can also tweak configuration according to your requirements. There are many configuration options available.