dev: gvim auto copy selected text(visual) to + register

458 views
Skip to first unread message

Sergey Vakulenko

unread,
Apr 23, 2012, 4:32:38 AM4/23/12
to vim_dev
Hi

I would like to propose this theme for GVim future feature (new
options for "set clipboard")
For someone who know very well gvim source code, its simple to
implement (i think).

Context of problem:
----------------------------

I wonder, how i can enable auto copy of selected text into '+'
register in Ubuntu (to share clipboard between apps).
i have set guioptions+=a

my test case (with behave mswin):
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

In Win xp this works perfectly. But not in X (my example is Ubuntu
11.10 )
I know that in X system this works different way and i tried to solve
this in this thread:

"gvim auto copy selected text to clipboard"
http://groups.google.com/group/vim_use/browse_thread/thread/d2d8516f9465301a/fae6c620e232af00?lnk=gst&q=vakulenko#fae6c620e232af00

http://stackoverflow.com/questions/10259366/gvim-auto-copy-selected-text-to-system-clipboard-to-share-it-with-apps

conclusion: its impossible configure gvim to auto copy selected buffer
in + register.
small resume of main (first) thread:

I have many proposition how to auto copy selected(visual) buffer in +
register.
But no one not work in way described in Subject. Major propositions:
1) use mouse click copy
2) ctrl-insert bind "y+
3) use third party clipboard.


There is no solutions but workarounds. Hence, it will be nice have
this feature in gvim.


ZyX

unread,
Apr 23, 2012, 1:13:45 PM4/23/12
to vim...@googlegroups.com
понедельник, 23 апреля 2012 г., 12:32:38 UTC+4 пользователь Sergey Vakulenko написал:
(G)Vim is already able to “copy” selected text to primary register (referenced inside Vim as *), to synchronize it with clipboard register use things like glipper/klipper/... (search for “clipboard manager” in your repository).

By the way, many (all) KDE applications use <C-S-Insert> shortcut to insert text from primary register (bad, I was told this is hardcoded), Opera can be configured to do this by pressing any key, you can also add a global shortcut to do the job, but I do not know exactly what should you do in this case.

Christian Brabandt

unread,
Apr 23, 2012, 5:12:51 PM4/23/12
to vim_dev
Hi Sergey!

On Mo, 23 Apr 2012, Sergey Vakulenko wrote:

> Hi
>
> I would like to propose this theme for GVim future feature (new
> options for "set clipboard")
> For someone who know very well gvim source code, its simple to
> implement (i think).
>
> Context of problem:
> ----------------------------
>
> I wonder, how i can enable auto copy of selected text into '+'
> register in Ubuntu (to share clipboard between apps).
> i have set guioptions+=a
>
> my test case (with behave mswin):
> 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

What is the problem with yanking the selection first?

> In Win xp this works perfectly. But not in X (my example is Ubuntu
> 11.10 )
> I know that in X system this works different way and i tried to solve
> this in this thread:
>
> "gvim auto copy selected text to clipboard"
> http://groups.google.com/group/vim_use/browse_thread/thread/d2d8516f9465301a/fae6c620e232af00?lnk=gst&q=vakulenko#fae6c620e232af00
>
> http://stackoverflow.com/questions/10259366/gvim-auto-copy-selected-text-to-system-clipboard-to-share-it-with-apps
>
> conclusion: its impossible configure gvim to auto copy selected buffer
> in + register.

It is not. Simply yank the selection and with 'cb' set to unnamedplus,
you'll have the contents available to paste with Ctrl-C in firefox or
use a clipboard manager like parcellite or glipper or klipper or
autocutsel to keep both X11 buffers in sync.

> small resume of main (first) thread:
>
> I have many proposition how to auto copy selected(visual) buffer in +
> register.
> But no one not work in way described in Subject. Major propositions:
> 1) use mouse click copy
> 2) ctrl-insert bind "y+
> 3) use third party clipboard.
>
>
> There is no solutions but workarounds. Hence, it will be nice have
> this feature in gvim.

Anyway, I have a patch, that changes the behaviour of the 'cb' option
when 'autoselect' is included to always copy the selection in both X11
buffers. But you'll lose the X11 clipboard then and I don't think this
is really useful.

Mit freundlichen Gr��en
Christian
--
Stirbt der Bauer schon im Mai, wird ein Fremdenzimmer frei.

Sergey Vakulenko

unread,
Apr 24, 2012, 11:29:57 AM4/24/12
to vim_dev
Hi Christian

> > There is no solutions but workarounds. Hence, it will be nice have
> > this feature in gvim.
>
> Anyway, I have a patch, that changes the behaviour of the 'cb' option
> when 'autoselect' is included to always copy the selection in both X11
> buffers. But you'll lose the X11 clipboard then and I don't think this
> is really useful.

I think this is particular side of vim philosophy:
You have many features, and you make your own choice, what to use
(useful for you), and what not.
I found this functionality very useful (im sure im not only one).
Hence, its would be nice have this feature in my vim.

I would like to test your patch

Thank you in advance

Sergey Vakulenko

unread,
Apr 27, 2012, 5:19:07 PM4/27/12
to vim_dev, Christian Brabandt
The problem is solved !
Big thanks to Christian Brabandt for patch.
First impression - its works like its should. Anyway, need a little a bit time to test this feature.
Its will be cool to see this patch as part of gvim application, like one of the options of clipboard.

In attach patch from Christian Brabandt

--
Cordialement
Sergiy Vakulenko
clipboard.diff

Li Xue

unread,
Mar 14, 2014, 5:09:53 PM3/14/14
to vim...@googlegroups.com, Christian Brabandt
Hi Christian,

Could you please tell me how to use your vim patch? I am new to vim.

Many thanks.

Li

Christian Brabandt

unread,
Mar 15, 2014, 8:33:12 AM3/15/14
to vim...@googlegroups.com

On Fr, 14 Mär 2014, Li Xue wrote:
> Hi Christian,
>
> Could you please tell me how to use your vim patch? I am new to vim.
>
> Many thanks.

If I remember correctly, this patch has been included in Vim with 7.3.074

This means, with all Vims that are newer (e.g. :version shows a higher
number than 7.3.073) you can simply set :set clipboard^=unnamedplus and
Vim will copy all yanks and deletes to the system clipboard. Read more
about it at :h 'clipboard (and look for the value unnamedplus)

Best,
Christian
--
Man muß, schon aus Welt, dem andern auch nicht das geringste
Unangenehme sagen, sobald man nicht ihn oder sich bessern damit will
oder kann. »Sage nicht zum Mietsherrn, deine Zimmer haben keine
Morgensonne.«
-- Jean Paul

Li Xue

unread,
Mar 15, 2014, 12:02:28 PM3/15/14
to vim...@googlegroups.com
Hi Christian,

I am using ssh (with -X option) from mac into a linux machine (Ubuntu 12.04.3 LTS). I use vim 7.4 to open files on the linux machine and had hoped to copy into the system
clipboard on my local mac machine. However, both "+yy and "*yy do not work for me. Do you happen to have any idea how to make it work? Many thanks.

Here is what I got after typing :version inside vim:

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

+arabic          +cmdline_info    -ebcdic          +fork()          +listcmds        +mouse_netterm   +persistent_undo +signs           +terminfo        +vreplace

+autocmd         +comments        +emacs_tags      +gettext         +localmap        +mouse_sgr       +postscript      +smartindent     +termresponse    +wildignore

+balloon_eval    +conceal         +eval            -hangul_input    +lua             -mouse_sysmouse  +printer         -sniff           +textobjects     +wildmenu

+browse          +cryptv          +ex_extra        +iconv           +menu            +mouse_urxvt     +profile         +startuptime     +title           +windows

++builtin_terms  +cscope          +extra_search    +insert_expand   +mksession       +mouse_xterm     +python          +statusline      +toolbar         +writebackup

+byte_offset     +cursorbind      +farsi           +jumplist        +modify_fname    +multi_byte      -python3         -sun_workshop    +user_commands   +X11

+cindent         +cursorshape     +file_in_path    +keymap          +mouse           +multi_lang      +quickfix        +syntax          +vertsplit       -xfontset

+clientserver    +dialog_con_gui  +find_in_path    +langmap         +mouseshape      -mzscheme        +reltime         +tag_binary      +virtualedit     +xim

+clipboard       +diff            +float           +libcall         +mouse_dec       +netbeans_intg   +rightleft       +tag_old_static  +visual          +xsmp_interact

+cmdline_compl   +digraphs        +folding         +linebreak       +mouse_gpm       +path_extra      +ruby            -tag_any_white   +visualextra     +xterm_clipboard

+cmdline_hist    +dnd             -footer          +lispindent      -mouse_jsbterm   +perl            +scrollbind      +tcl             +viminfo         -xterm_save






--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/G1Def0Fj27U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xue, Li
Post-doctoral Research Associate
College of Information Sciences and Technology
Penn State University
Email: lx...@ist.psu.edu
Web site: http://www.cs.iastate.edu/~lixue/

Christian Brabandt

unread,
Mar 15, 2014, 12:37:51 PM3/15/14
to vim...@googlegroups.com
Hi Li!

On Sa, 15 Mär 2014, Li Xue wrote:

> Hi Christian,
>
I am not sure, this is supposed to work and I don't have any experience
with Mac so I can't be of any help, sorry. You might need to start an
X11 server on your Mac, but I am not sure. You might also want to try
using ssh -Y option.

Best,
Christian
--
Leiden, Irrtum und Widerstandskraft halten das Leben lebendig.
-- Gottfried Keller

Li Xue

unread,
Mar 16, 2014, 11:43:47 AM3/16/14
to vim...@googlegroups.com
Hi Christian,

Thanks for your reminder of the x11. You are right that I need to start a X11 server. If I start X11 server, sometimes I can copy from a remote vim to the clipboard on my local mac. But if I log out of my account from my mac machine, it does not work again. Do you think it might be a bug in vim?

Here are my steps:

1. start xquartz and open a terminal inside xquartz
2. from this terminal, type ssh -X remote_host_name (I also tried -Y)
3. for the remote vim I set ":set clipboard=unnamedplus,unnamed,autoselect,exclude:cons\|linux"
4. use vim open a file from the remote_host_name
5. inside vim, type yy to yank a line into system clipboard, and if I am lucky with this ssh session, I can paste that line into a text editor on my local mac machine. 

To test whether xterm forwarding is working properly, inside the ssh session, I also typed "xterm &", and my local mac machine can always open xterm.

Li

LCD 47

unread,
Mar 16, 2014, 2:02:29 PM3/16/14
to vim...@googlegroups.com
On 16 March 2014, Li Xue <lx...@ist.psu.edu> wrote:
> Hi Christian,
>
> Thanks for your reminder of the x11. You are right that I need to
> start a X11 server. If I start X11 server, sometimes I can copy from
> a remote vim to the clipboard on my local mac. But if I log out of my
> account from my mac machine, it does not work again. Do you think it
> might be a bug in vim?

You need to run an X server on your machine, and you need a ssh
connection with ForwardX11Trusted, that is, "ssh -Y" (and it actually
has to succeed; see "ssh -v -Y" to make sure). "ssh -X" is not enough.

> Here are my steps:
>
> 1. start xquartz and open a terminal inside xquartz
> 2. from this terminal, type ssh -X remote_host_name (I also tried -Y)
> 3. for the remote vim I set ":set
> clipboard=unnamedplus,unnamed,autoselect,exclude:cons\|linux"

It's probably a good idea to drop "unnamed", and escape '\'. Put
something like this in your remote vimrc:

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

This will make Vim use the '+' register for all yank, delete,
change, and put operations, which many people find easier to work with.

> 4. use vim open a file from the remote_host_name
> 5. inside vim, type yy to yank a line into system clipboard, and if
> I am lucky with this ssh session, I can paste that line into a text
> editor on my local mac machine.
[...]

Open xclipboard on the local machine, and yank a line in the remote
vim. You should see the line appear in xclipboard, and this should work
both with a remote gvim, and with a remote console vim.

/lcd

Li Xue

unread,
Mar 16, 2014, 2:23:55 PM3/16/14
to vim...@googlegroups.com
Hi,

Xquartz is x sever. And I tried ssh - Y.

LCD 47

unread,
Mar 16, 2014, 2:49:48 PM3/16/14
to vim...@googlegroups.com
On 16 March 2014, Li Xue <me.l...@gmail.com> wrote:
> Hi,
>
> Xquartz is x sever. And I tried ssh - Y.

Yes, what I'm saying is that:

(1) it won't work with "ssh -X";
(2) it won't work with "ssh -Y" if trusted forwarding fails silently;
(3) having both unnamedplus and unnamed in &clipboard makes it harder
for you to see whether it works or not;
(4) you should run xclipboard both on the local and the remote machine,
to find out where your yanks end up.

/lcd

Li Xue

unread,
Mar 16, 2014, 4:11:39 PM3/16/14
to vim...@googlegroups.com
Hi lcd,

Thanks for your reply. 

Do you mean that I should try ssh -v -Y?
I am new to vim. I do not know how to run xclipboard both on the local and the remote machine. Could you please give me a more detailed instruction?

Do you happen to have any idea why my steps randomly work in different ssh sessions?

Li



    /lcd

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/G1Def0Fj27U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LCD 47

unread,
Mar 16, 2014, 5:11:28 PM3/16/14
to vim...@googlegroups.com
On 16 March 2014, Li Xue <lx...@ist.psu.edu> wrote:
> Hi lcd,
>
> Thanks for your reply.
>
> Do you mean that I should try ssh -v -Y?

The difference between "-X" and "-Y" is that with "-X" the remote
host's connections to your X server are subject to X11 security
restrictions, while with "-Y" they aren't. Adding "-v" makes ssh print
debugging messages. You should run it once, to make sure "-Y" succeeds.
If you get a message such as

X11 forwarding request failed on channel 0

before ssh gives you the prompt, it didn't work, and you need to change
the sshd configuration on the remote machine. If you don't get that
message you're fine and you can forget about "-v".

> I am new to vim. I do not know how to run xclipboard both on the local
> and the remote machine. Could you please give me a more detailed
> instruction?

(1) edit vimrc on the remote machine, and change clipboard as I
mentioned in the previous message;
(2) on the remote machine, run "xclipboard &"; this should open a small
window;
(3) on the remote machine run vim and yank a few lines; you should see
them appearing in the small window;
(4) close the small window;
(5) on the local machine, open a new terminal and run "xclipboard"; this
should open another small window;
(6) on the remote machine run vim again and yank a few lines; you should
see them again appearing in the small window.

Keep the xclipboard window open and watch it while you work. If you
see your yanks appearing there, remote transmission works, regardless of
whether you can actually paste the results on the local machine.

> Do you happen to have any idea why my steps *randomly* work in
> different ssh sessions?

Failing randomly seems improbable. More likely either your yanks
get to the '*' register and they aren't transmitted over the line (only
the ones in the '+' register are sent), or your testing procedure is
flawed in other way. The definitive test is whether your yanks appear
in xclipboard.

/lcd

Li Xue

unread,
Mar 16, 2014, 8:46:19 PM3/16/14
to vim...@googlegroups.com
Hi lcd,

Many thanks for your detailed instructions and explanations! I really appreciate it!

I did the steps you told me and in fact my yanks can appear on both the remote and local xclipboard windows, even though I still cannot paste the results on the local machine. So the remote transmission works.

Do you happen to have any idea why I cannot paste my yanks on the local machine?

Many thanks.

Li





    /lcd

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/G1Def0Fj27U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LCD 47

unread,
Mar 17, 2014, 1:39:33 AM3/17/14
to vim...@googlegroups.com
On 16 March 2014, Li Xue <lx...@ist.psu.edu> wrote:
> Hi lcd,
>
> Many thanks for your detailed instructions and explanations! I really
> appreciate it!
>
> I did the steps you told me and in fact my yanks can appear on both
> the remote and local xclipboard windows, even though I still cannot
> paste the results on the local machine. So the remote transmission
> works.

Excellent!

> Do you happen to have any idea why I cannot paste my yanks on the
> local machine?
[...]

Your experiment above shows that the problem is local to your Mac
machine. Now, I don't know much about Mac OS, but I suppose you need
version of Vim with +clipboard, +X11, and +xterm_clipboard, and you
might want to add something like this to your vimrc:

set clipboard=unnamedplus,autoselect

(it's probably safe to leave alone the linux console exception, since
you won't run into it on Mac). After that, you should be able to open
xclipboard, type something there, and than paste it in a local Vim. If
Vim can't paste the contents of the clipboard, the problem is incomplete
(or buggy) integration between your Vim and X11. I'm not sure what you
can do about that; as I understand there are several implementations of
Vim for Mac, perhaps try a different one.

/lcd

Li Xue

unread,
Mar 17, 2014, 2:10:08 PM3/17/14
to vim...@googlegroups.com
Hi lcd,

Many thanks for your help these days.

You are right. My vim version has only +clipboard but does not support xterm_clipboard. 

I have not found a version of vim for mac that can support xterm_clipboard yet. But I am glad to find out the source of the problem. 

Li



    /lcd

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/G1Def0Fj27U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages