Clipboard functionality on Unix/Windows

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Clipboard functionality on Unix/Windows

Ven Tadipatri
So after struggling for a while trying to integrate vi with the system
clipboard, I figured it out, and thought I might share it with others

On Windows (from cygwin):
vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!cat >/dev/clipboard<CR>u

On Linux machines (if you have xclip):
vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u

I think to copy only part of the line, I had to use marks to keep
track of the selection length, otherwise the cat or xclip command is
executed on the whole line.  Also copying wiped out the line that I
was on, so I had to undo the command after the copy.
I think there is a buffer in vi that corresponds to the system
clipboard, but couldn't get that to work either. Yes it's an ugly
sequence of commands, but once it's in in my .vimrc I can copy and
paste from vi into other applications both on my Windows and Linux
machines

Thanks,
Ven

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Gary Johnson-4
On 2010-09-16, Ven Tadipatri wrote:
> So after struggling for a while trying to integrate vi with the system
> clipboard, I figured it out, and thought I might share it with others
>
> On Windows (from cygwin):
> vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!cat >/dev/clipboard<CR>u
>
> On Linux machines (if you have xclip):
> vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u

If you have to do all that to copy from vim to the clipboard, your
system is not properly configured.  It may be that the vi or vim
you're using was not built with support for X11 or the
xterm_clipboard.  Some distributions come with a "vi" that is the
tiny version of Vim, without support many features at all, and "vim"
is often built without support for X11.  Try running Vim in a
terminal as "gvim -v".  That will use the gvim binary, which does
have X11 support, but in console mode.

Regards,
Gary

--
You received this message from the "vim_use" 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
BC
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

BC
In reply to this post by Ven Tadipatri


On Sep 16, 12:14 pm, Ven Tadipatri <[hidden email]> wrote:

> I think there is a buffer in vi that corresponds to the system
> clipboard, but couldn't get that to work either. Yes it's an ugly
> sequence of commands, but once it's in in my .vimrc I can copy and
> paste from vi into other applications both on my Windows and Linux
> machines

Yes, unfortunately the + and * registers won't cooperate between
Cygwin and the Windows clipboard.
Some other approaches to making the Cygwin clipboard usable are
detailed here:
http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim

and there's a plug-in called "fakeclip" you might be interested in
here:
http://www.vim.org/scripts/script.php?script_id=2098

I'm not using Cygwin currently, but I remember being stumped by the
same issue when I was.  Does anyone know if there are alternatives to
Cygwin that could give a Windows user a *nix command line that one
could access via Gvim, with a good set of utilities that would
integrate more easily with the Windows clipboard?  I'm trying to avoid
Cygwin (too slow, and I found the installation a pain) but I've been
wanting to try to learn some bash scripting.  Having a decent terminal
emulator would be a plus too -- is Cygwin my only option?

Thanks.
BC

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

scott-268
On Thursday 16 September 2010 19:48:15 BC wrote:

> same issue when I was.  Does anyone know if there are
> alternatives to Cygwin that could give a Windows user a *nix
> command line that one could access via Gvim, with a good set
> of utilities that would integrate more easily with the
> Windows clipboard?  I'm trying to avoid Cygwin (too slow, and
> I found the installation a pain) but I've been wanting to try
> to learn some bash scripting.  Having a decent terminal
> emulator would be a plus too -- is Cygwin my only option?

i found i could be most productive in the windows shell -- i
forget if it was cmd.exe or command.com

with the utilities from

    http://unxutils.sourceforge.net

installed in your path, you'll be amazed what you can do

sc

--
You received this message from the "vim_use" 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
BC
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

BC


On Sep 16, 10:34 pm, sc <[hidden email]> wrote:

> i found i could be most productive in the windows shell -- i
> forget if it was cmd.exe or command.com
>
> with the utilities from
>
>    http://unxutils.sourceforge.net
>
> installed in your path, you'll be amazed what you can do

Thanks, sc.  I'll give that a try.

BC

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Christian Brabandt
In reply to this post by BC
On Fri, September 17, 2010 2:48 am, BC wrote:
> I'm not using Cygwin currently, but I remember being stumped by the
> same issue when I was.  Does anyone know if there are alternatives to
> Cygwin that could give a Windows user a *nix command line that one
> could access via Gvim, with a good set of utilities that would
> integrate more easily with the Windows clipboard?  I'm trying to avoid
> Cygwin (too slow, and I found the installation a pain) but I've been
> wanting to try to learn some bash scripting.  Having a decent terminal
> emulator would be a plus too -- is Cygwin my only option?

There is a patch, that enables Cygwin vim to access the windows
clipboard.
http://groups.google.com/group/vim_dev/web/vim-patches

regards,
Christian

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Ven Tadipatri
On Fri, Sep 17, 2010 at 2:29 AM, Christian Brabandt <[hidden email]> wrote:
> On Fri, September 17, 2010 2:48 am, BC wrote:
>
> There is a patch, that enables Cygwin vim to access the windows
> clipboard.
> http://groups.google.com/group/vim_dev/web/vim-patches

Can't it do that by default? I thought /dev/clipboard is available
when you install Cygwin, and points to the windows clipboard.

Thanks,
Ven

>
> regards,
> Christian
>

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Ven Tadipatri
In reply to this post by Gary Johnson-4
On Thu, Sep 16, 2010 at 1:55 PM, Gary Johnson <[hidden email]> wrote:

> On 2010-09-16, Ven Tadipatri wrote:
>> So after struggling for a while trying to integrate vi with the system
>> clipboard, I figured it out, and thought I might share it with others
>>
>> On Windows (from cygwin):
>> vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!cat >/dev/clipboard<CR>u
>>
>> On Linux machines (if you have xclip):
>> vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u
>
> If you have to do all that to copy from vim to the clipboard, your
> system is not properly configured.  It may be that the vi or vim

I have no clue how my system is configured, but I'm almost positive
that there's something wrong
with my vi setup.

> you're using was not built with support for X11 or the
> xterm_clipboard.  Some distributions come with a "vi" that is the
> tiny version of Vim, without support many features at all, and "vim"
> is often built without support for X11.  Try running Vim in a
> terminal as "gvim -v".  That will use the gvim binary, which does

Wow, thank you so much for that tip -  You have no idea how many hours
I spent trying to get copy and paste to work. When I tried gvim -v, I
was able to access the +buffer to copy. Could you please add this to
the vim wiki, because I think it could seriously benefit a lot of
users.
  Except now I have a slight problem that when I try to do shift+F4,
which I mapped to a shortcut, it prints out "2S" on the line. This
worked fine when I ran vi before, but it looks like some sort of weird
keymapping issue.
   I hope the rest of the features work as expected. Does running gvim
-v require X11? I'm wondering if it will still work when I ssh into a
remote machine.


> have X11 support, but in console mode.
>
> Regards,
> Gary
>

Thanks,
Ven

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

scott-268
On Thursday 07 October 2010 14:44:44 Ven Tadipatri wrote:

>  Except now I have a slight problem that when I try to do
> shift+F4, which I mapped to a shortcut, it prints out "2S" on
> the line. This worked fine when I ran vi before, but it looks
> like some sort of weird keymapping issue.

if you still have

    set paste

in your .vimrc, take it out

sc

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Gary Johnson-4
In reply to this post by Ven Tadipatri
On 2010-10-07, Ven Tadipatri wrote:

>    I hope the rest of the features work as expected. Does running gvim
> -v require X11? I'm wondering if it will still work when I ssh into a
> remote machine.

No, it does not require X11 to run, it just makes use of certain X11
features if they are available.

Using it over an ssh connection should work fine except for those
features that require X11.  I _think_ that you can use those
features over as ssh connection as well if you use ssh's -Y option,
but I can't test that at the moment.

Regards,
Gary

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Christian Brabandt
In reply to this post by Ven Tadipatri
On Thu, October 7, 2010 9:37 pm, Ven Tadipatri wrote:
> On Fri, Sep 17, 2010 at 2:29 AM, Christian Brabandt wrote:
>> There is a patch, that enables Cygwin vim to access the windows
>> clipboard.
>> http://groups.google.com/group/vim_dev/web/vim-patches
>
> Can't it do that by default?

Don't know. I've never had the need for the feature.

> I thought /dev/clipboard is available
> when you install Cygwin, and points to the windows clipboard.

Have you tried the patch? If enough people test the patch and report back
that it works without any problems, there is a good chance, that
the patch will eventually be included into main Vim. Or to say it with
other words: Vim is OpenSource, it's your chance to give something back ;)

regards,
Christian

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Sean-130
I tried the following 3 steps under cygwin but failed. Any thing do I
miss?


cd /usr/share/vim && hg pull -u
cd /usr/share/vim/src && patch -f <
vim_on_cygwin_using_win32_clipboard__full__2008_12_21_001.patch >&
logfile
cat logfile

----------------------------- error log msg below
patching file term.c
Hunk #1 FAILED at 1922.
1 out of 1 hunk FAILED -- saving rejects to file term.c.rej
patching file Make_cyg.mak
Hunk #1 FAILED at 420.
1 out of 1 hunk FAILED -- saving rejects to file Make_cyg.mak.rej
patching file configure.in
Hunk #1 FAILED at 2023.
1 out of 1 hunk FAILED -- saving rejects to file configure.in.rej
patching file Make_ming.mak
Hunk #1 FAILED at 388.
1 out of 1 hunk FAILED -- saving rejects to file Make_ming.mak.rej
patching file winclip.pro
can't find file to patch at input line 91
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|
|Index: proto/os_mswin.pro
|===================================================================
|--- proto/os_mswin.pro (revision 1296)
|+++ proto/os_mswin.pro (working copy)
--------------------------
No file to patch.  Skipping patch.
1 out of 1 hunk ignored
patching file Make_w16.mak
Hunk #1 FAILED at 107.
1 out of 1 hunk FAILED -- saving rejects to file Make_w16.mak.rej
patching file vim.h
Hunk #1 FAILED at 1792.
1 out of 1 hunk FAILED -- saving rejects to file vim.h.rej
patching file Make_bc5.mak
Hunk #1 FAILED at 638.
1 out of 1 hunk FAILED -- saving rejects to file Make_bc5.mak.rej
patching file feature.h
Hunk #1 FAILED at 1066.
1 out of 1 hunk FAILED -- saving rejects to file feature.h.rej
patching file proto.h
Hunk #1 FAILED at 47.
1 out of 1 hunk FAILED -- saving rejects to file proto.h.rej
patching file Makefile
Hunk #1 FAILED at 1552.
Hunk #2 succeeded at 1771 with fuzz 2 (offset 77 lines).
Hunk #3 succeeded at 2621 with fuzz 2 (offset 119 lines).
Hunk #4 FAILED at 2953.
2 out of 4 hunks FAILED -- saving rejects to file Makefile.rej
patching file config.h.in
Hunk #1 FAILED at 378.
1 out of 1 hunk FAILED -- saving rejects to file config.h.in.rej
patching file mbyte.c
Hunk #1 FAILED at 591.
Hunk #2 FAILED at 3146.
Hunk #3 FAILED at 4444.
3 out of 3 hunks FAILED -- saving rejects to file mbyte.c.rej
patching file os_unix.c
Hunk #1 succeeded at 1192 with fuzz 2 (offset 36 lines).
patching file os_mswin.c
Hunk #1 FAILED at 889.
1 out of 1 hunk FAILED -- saving rejects to file os_mswin.c.rej
patching file os_win32.c
Hunk #1 FAILED at 1679.
Hunk #2 FAILED at 2162.
2 out of 2 hunks FAILED -- saving rejects to file os_win32.c.rej
patching file Make_ivc.mak
Hunk #1 FAILED at 240.
Hunk #2 succeeded at 610 (offset 15 lines).
1 out of 2 hunks FAILED -- saving rejects to file Make_ivc.mak.rej
patching file Make_mvc.mak
Hunk #1 FAILED at 473.
Hunk #2 succeeded at 1106 with fuzz 2 (offset 130 lines).
Hunk #3 FAILED at 1207.
2 out of 3 hunks FAILED -- saving rejects to file Make_mvc.mak.rej
patching file configure
Hunk #1 FAILED at 10218.
1 out of 1 hunk FAILED -- saving rejects to file configure.rej
patching file winclip.c
patching file globals.h
Hunk #1 FAILED at 769.
1 out of 1 hunk FAILED -- saving rejects to file globals.h.rej
-----------------------------

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Christian Brabandt
On Fri, October 15, 2010 4:59 am, Sean wrote:

> I tried the following 3 steps under cygwin but failed. Any thing do I
> miss?
>
>
> cd /usr/share/vim && hg pull -u
> cd /usr/share/vim/src && patch -f <
> vim_on_cygwin_using_win32_clipboard__full__2008_12_21_001.patch >&
> logfile
> cat logfile
>
> ----------------------------- error log msg below
[...]
I really don't know. Instead of using the full patch, try the simplified
version. Maybe that will apply cleanly. If not, I suggested contacting
the author of the patch Anton Sharonov and ask him for guidance.

You might also want to try the vim-dev mailinglist. In either way, please
report back there, so Bram will know about the status of the patch and
if it works without problems, might eventually include it.

regards,
Christian

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Sean-130
Same error using
vim_on_cygwin_using_win32_clipboard__simple__2008_12_21_001.patch.
Wish I could get help from Anton Sharonov :))

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Christian Brabandt
Hi Sean!

On Do, 14 Okt 2010, Sean wrote:

> Same error using
> vim_on_cygwin_using_win32_clipboard__simple__2008_12_21_001.patch.
> Wish I could get help from Anton Sharonov :))

Well, I took a look and could successfully patch Vim 7.3 sources with
the simple patch. The patch applied with offsets and I needed to
manually patch config.h.in but after fixing that, it compiled
successfully. How can I test, that it works? Do I need to compile a
Cygwin binary or the Windows binary?

I simply cross compiled a Windows binary. If I need to compile a Cygwin
binary, I need to start all over again on Windows and need to get all
available tools for Cygwin, which I feel is really painful ;(

regards,
Christian

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Sean-130


On Oct 17, 9:49 am, Christian Brabandt <[hidden email]> wrote:

> Hi Sean!
>
> On Do, 14 Okt 2010, Sean wrote:
>
> > Same error using
> > vim_on_cygwin_using_win32_clipboard__simple__2008_12_21_001.patch.
> > Wish I could get help from Anton Sharonov :))
>
> Well, I took a look and could successfully patch Vim 7.3 sources with
> the simple patch. The patch applied with offsets and I needed to
> manually patch config.h.in but after fixing that, it compiled
> successfully. How can I test, that it works? Do I need to compile a
> Cygwin binary or the Windows binary?
>
> I simply cross compiled a Windows binary. If I need to compile a Cygwin
> binary, I need to start all over again on Windows and need to get all
> available tools for Cygwin, which I feel is really painful ;(
>
> regards,
> Christian


Hi Christian,

What is wrong with these steps?

--------------------------------
cd /usr/share/vim
hg pull -u
cd /usr/share/vim/src
patch -f <
vim_on_cygwin_using_win32_clipboard__simple__2008_12_21_001.patch >&
logfile
--------------------------------

Thanks
Sean


PS: cat logfile  ==>
patching file term.c
Hunk #1 FAILED at 1922.
1 out of 1 hunk FAILED -- saving rejects to file term.c.rej
patching file configure.in
Hunk #1 FAILED at 2023.
1 out of 1 hunk FAILED -- saving rejects to file configure.in.rej
patching file vim.h
Hunk #1 FAILED at 1792.
1 out of 1 hunk FAILED -- saving rejects to file vim.h.rej
patching file feature.h
Hunk #1 FAILED at 1066.
1 out of 1 hunk FAILED -- saving rejects to file feature.h.rej
patching file Makefile
Hunk #1 FAILED at 1467.
Hunk #2 succeeded at 2635 with fuzz 2 (offset 136 lines).
1 out of 2 hunks FAILED -- saving rejects to file Makefile.rej
patching file config.h.in
Hunk #1 FAILED at 378.
1 out of 1 hunk FAILED -- saving rejects to file config.h.in.rej
patching file mbyte.c
Hunk #1 FAILED at 591.
Hunk #2 FAILED at 3146.
2 out of 2 hunks FAILED -- saving rejects to file mbyte.c.rej
patching file os_unix.c
Hunk #1 succeeded at 1201 with fuzz 2 (offset 45 lines).
patching file os_mswin.c
Hunk #1 succeeded at 13 with fuzz 2 (offset -12 lines).
Hunk #2 succeeded at 935 with fuzz 2 (offset 34 lines).
Hunk #3 succeeded at 1109 with fuzz 2 (offset 64 lines).
Hunk #4 succeeded at 2494 with fuzz 2 (offset 866 lines).
Hunk #5 FAILED at 4365.
1 out of 5 hunks FAILED -- saving rejects to file os_mswin.c.rej
patching file os_win32.c
Hunk #1 FAILED at 1679.
Hunk #2 FAILED at 2162.
2 out of 2 hunks FAILED -- saving rejects to file os_win32.c.rej
patching file configure
Hunk #1 FAILED at 10218.
1 out of 1 hunk FAILED -- saving rejects to file configure.rej
patching file globals.h
Hunk #1 FAILED at 769.
1 out of 1 hunk FAILED -- saving rejects to file globals.h.rej

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard functionality on Unix/Windows

Christian Brabandt
Hi Sean!

On Mo, 18 Okt 2010, Sean wrote:

> What is wrong with these steps?
>
> --------------------------------
> cd /usr/share/vim
> hg pull -u
> cd /usr/share/vim/src
> patch -f <
> vim_on_cygwin_using_win32_clipboard__simple__2008_12_21_001.patch >&
> logfile
> --------------------------------

Are you missing a -p0 as paramter to patch?

I could successfully patch the source, but hadn't had luck compiling it
on Cygwin. BTW: I think the simple patch is wrong. It changes the
configure script, which you wouldn't use when compiling on Cygwin (there
you would use Make_cyg.mak), and which in turn breaks compiling a unix
binary.

I tried compiling on Cygwin, but linking fails miserably ;(

regards,
Christian

--
You received this message from the "vim_use" 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