Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut to the system clipboard from Vim on Ubuntu

Tags:

vim

ubuntu

I am using Ubuntu 12.04 Beta and Vim that has come with it. I am trying to use Vim to copy the content of a text file to Chrome browser. I have tried +, * y and all its variants. I have tried to :set clipboard=unnamed and :set clipboard=unnamedplus. Not working. I am not trying to use xclip, or GVim or any of that. I tried with xclip (not a standard package in Ubuntu 12.04), but that too does not work, also too much effort.

How do I copy the text to the clipboard and then paste anywhere, like Chrome?

like image 868
Gattoo Avatar asked Apr 11 '12 07:04

Gattoo


People also ask

How can I copy text to the system clipboard from vim?

In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard. Go to any external application and CMD + v to paste.

How do I copy to clipboard in Ubuntu?

To copy text or command from Ubuntu terminal, press “CTRL+Shift+c” To paste text or command in Ubuntu terminal, press “CTRL+Shift+v” To copy text or command from outside of the Ubuntu terminal, press “CTRL+c”

How do I copy text from vi editor to clipboard?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do I copy an entire file to the clipboard in vi?

Another easy way to copy the entire file if you're having problems using VI, is just by typing "cat filename". It will echo the file to screen and then you can just scroll up and down and copy/paste.


2 Answers

Your version of Vim doesn't support X, which is required for clipboard access. By default, Ubuntu ships several builds of vim and only the GUI variant supports clipboard access. I always recompile vim from source so that a single vim (with symlinks for gvim etc) supports everything required (including :gui to switch from command line to GUI version). It's really very easy to do:

# Get the compile-dependencies of vim sudo apt-get build-dep vim # If you haven't got mercurial, get it sudo apt-get install mercurial # Get the source hg clone https://vim.googlecode.com/hg/ vim_source # Compile it cd vim_source ./configure \     --enable-perlinterp=dynamic \     --enable-pythoninterp=dynamic \     --enable-rubyinterp=dynamic \     --enable-cscope \     --enable-gui=auto \     --enable-gtk2-check \     --enable-gnome-check \     --with-features=huge \     --with-x \     --with-compiledby="Your Name <[email protected]>" \     --with-python-config-dir=/usr/lib/python2.7/config make && sudo make install 

That will install it in /usr/local, so make sure that's in your PATH before /usr and it will be used instead of the Ubuntu versions.

like image 73
DrAl Avatar answered Sep 27 '22 01:09

DrAl


The output from vim --version should show something like this:

Huge version with GTK2-GNOME GUI.  Features included (+) or not (-): 

and further down in the output you should see stuff like +Xll:

+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim  +xsmp_interact +xterm_clipboard -xterm_save  

That means your console vim can copy/paste to/from the X11 clipboard.

Try apt-get install vim-gtk

like image 30
sashang Avatar answered Sep 25 '22 01:09

sashang