2

I wonder, how i can enable auto copy of selected text into '+' register in Ubuntu (to share clipboard between apps)? On win XP, i have

set guioptions+=a

and its works perfectly, but not in Ubuntu 11.10.

Also, i tried

set clipboard=unnamedplus,unnamed,autoselect,exclude:cons\|linux.

but without success.

Please do not offer hand-click solutions like vmap <C-Insert> "+y and mouse copy/paste.

test case (with "behave mswin" option):

  1. open gvim

  2. shift-v, move cursor and Esc (select lines in visual mode)

  3. go to firefox and click ctrl-v or ctrl-Insert to paste text

Solution

In this thread, problem was solved.

You need to apply patch from Christian Brabandt.

Also, if you have problem with paste with shift-insert after recompilation in ubuntu, you can add this in your vimrc:

if has("gui_running")
    map <silent> <S-Insert> "+p
    cmap <S-Insert> <C-R>+
    imap <silent> <S-Insert> <Esc>"+pa
endif
D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
Sergey Vakulenko
  • 1,655
  • 18
  • 23

2 Answers2

0

Does "+y work? It's not a suggestion: if this command doesn't work, you may have some underlying problems that prevent a simple solution. So it needs to be checked first, even if it sounds stupid.

set clipboard+=unnamedplus is enough if your version of Vim supports it. Mine is 7.3.35 and it doesn't work (Vim doesn't complain, though).

I don't know exactly which patch introduced unnamedplus but you can do :help 'clipboard' (with the single quotes) to have a list of available options. If unnamedplus is listed, the snippet above should fix your problem. If it's not there you won't be able to use it (obviously): time to re-assess your "do not offer hand-click solutions like vmap "+y and mouse copy/paste" requirement or compile a more recent version of Vim.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • In Linux exist two global clipboards, + and * . Your answer not handle * clipboard. I advice you to read thread in Solution section, to understand more the problem. – Sergey Vakulenko Jun 05 '12 at 12:30
  • The OP had some missing text due to missing code formatting; that snippet should read `vmap "+y` – D. Ben Knoble Dec 15 '19 at 14:34
0

Try following:

set guioptions+=P

Explanation:

TLDR: a puts text into "* register. P puts text into "+ register

From :help guioptions

'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.

'P' Like autoselect but using the "+ register instead of the "* register.

Nilesh Kevlani
  • 1,278
  • 1
  • 10
  • 10