I can cat a file, copy and paste text with the middle button or shift-insert.
How can I copy text in vim and paste it from the system clipboard?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
You need to have Vim with the
xtermclipboard features compiled in. In Ubuntu, these are only available with the vim GUI packages (
Once you install one of these, you can copy to (and paste from) the clipboard registers (
+). From this very informative post on Vi and Vim:
For X11-based systems (ie. Linux and most other UNIX-like systems) there are 2 clipboards, which are independent of each other:
- PRIMARY - This is copy-on-select, and can be pasted with the middle mouse button.
- CLIPBOARD - This is copied with (usually)
^C, and pasted with
^V(It's like MS Windows).
Vim has 2 special registers corresponding to these clipboards:
*uses PRIMARY; mnemonic: star is select (for copy-on-select)
+uses CLIPBOARD; mnemonic: CTRL + C (for the common keybind)
To copy to a register, you precede the copy command (
" and the name of the register (
*, for example).
"*y, then middle-click to paste, or
"+y and ShiftInsert to paste.
A quite interesting solution comes from this question. Install xclip, then pipe output of a command to xclip(
cat file | xclip -selection clipboard for instance ), and then paste it anywhere, (if that's in terminal - use Ctrl ShiftV
). Now , turns out you can actually shorten that command to
xclip -sel clip, which is not exactly apparent from reading man page or examples there.
I had issue because my vim was not supporting clipboard:
vim --version | grep clip -clipboard +insert_expand +path_extra +user_commands +emacs_tags -mouseshape +startuptime -xterm_clipboard
I installed vim-gnome (which support clipboard) and then checked again:
vim --version | grep clipboard +clipboard +insert_expand +path_extra +user_commands +emacs_tags +mouseshape +startuptime +xterm_clipboard
Now I am able to copy and paste using "+y and "+p respectively.