Why I can't paste and copy from other program in Vim?

Make sure that your Vim binary supports +clipboard, check output of vim --version or :version inside of Vim and check for that setting there.

$ vim --version | grep clipboard

Distributions often ship multiple versions of the Vim package, you'll want to install a more featureful one that is built with most features enabled and typically one that includes the GUI (gvim), since clipboard support on Linux requires X11 and that's typically bundled with the GUI version of Vim.

On Ubuntu 18.04, that's most likely the vim-gtk3 package, use sudo apt-get install vim-gtk3 or similar to install that package if you don't have it yet.

Also make sure the vim binary you get is the one coming from that package. (I believe you can use sudo update-alternatives --config vim to set that up. You can also use sudo update-alternatives --config editor to configure the default editor in your system.)

Finally, clipboard support needs to connect to X11, so make sure the $DISPLAY variable is set and set correctly when you start Vim. If you're starting Vim from a local terminal (gnome-terminal or xterm or rxvt or similar) that's typically the case... But if you're using something like tmux or screen and reconnecting to a session you might have opened outside of this GUI session, you might have a $DISPLAY that's out of sync... Update that variable to the correct value to fix that if necessary.

Tags:

Vim

Ubuntu