Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selection automatically put into X11 clipboard - VIM

Tags:

vim

In my previous Linux install, when I selected some text in visual mode (without the mouse!), it would automatically put it in my X11 clipboard. Then I could naturally paste this text anywhere else using the mouse middle button.

With my new Linux installation, this doesn't work anymore (merely selecting text in visual mode doesn't put it in X11 clipboard anymore).

How can I get this nice feature back?

(I am not interested into the "*y or "+y solutions, which by the way don't work on my system.)

Thanks in advance!

like image 340
subshift Avatar asked Nov 03 '11 15:11

subshift


2 Answers

The visual selection (v, V, or CTRL-V) can automatically be copied to the X11 selection (* buffer).

In non-gui mode the clipboard option controls this (only supported if +xterm_clipboard appears when you type vim --version). In gui mode guioptions controls it.

This makes all Visual mode selections automatically go to the X11 primary selection:

set clipboard+=autoselect
set guioptions+=a

This turns it off:

set clipboard-=autoselect
set guioptions-=a

In vim see:

help 'clipboard'

(single quotes required)

like image 67
Acorn Avatar answered Oct 18 '22 20:10

Acorn


Use:

set guioptions+=a

This works with the GUI (Gvim). Reference is at :help guioptions_a.

                        *guioptions_a* *'go-a'*
  'a'   Autoselect:  If present, then whenever VISUAL mode is started,
    or the Visual area extended, Vim tries to become the owner of
    the windowing system's global selection.  This means that the
    Visually highlighted text is available for pasting into other
    applications as well as into Vim itself.  When the Visual mode
    ends, possibly due to an operation on the text, or when an
    application wants to paste the selection, the highlighted text
    is automatically yanked into the "* selection register.
    Thus the selection is still available for pasting into other
    applications after the VISUAL mode has ended.
        If not present, then Vim won't become the owner of the
    windowing system's global selection unless explicitly told to
    by a yank or delete operation for the "* register.
    The same applies to the modeless selection.
like image 3
Benoit Avatar answered Oct 18 '22 20:10

Benoit