echoing the contents of a registry to a /dev device

19 views
Skip to first unread message

Chris Sutcliffe

unread,
Apr 18, 2012, 9:11:49 AM4/18/12
to vim...@googlegroups.com
Hi All,

I'm trying to figure out a way to dump the contents of the '@@'
registry (i.e. the registry populated by the yank command) to the
/dev/clipboard device in Cygwin. Basically I'm trying:

silent exe "!echo \"" . <somehow access @@ > . "\" > /dev/clipboard"

But I can't figure out how to access @@. Simply trying:

silent exe "!echo \"" . @@ . "\" > /dev/clipboard"

Didn't work.

Any help would be greatly apprecaited, thank you!

Chris

--
Chris Sutcliffe
http://emergedesktop.org
http://www.google.com/profiles/ir0nh34d

Tim Chase

unread,
Apr 18, 2012, 9:58:12 AM4/18/12
to vim...@googlegroups.com
On 04/18/12 08:11, Chris Sutcliffe wrote:
> I'm trying to figure out a way to dump the contents of the '@@'
> registry (i.e. the registry populated by the yank command) to the
> /dev/clipboard device in Cygwin. Basically I'm trying:

You're awfully close, but I think you're reaching for the wrong
register. The

@"

register contains the most recent yank, not "@@". So you might try

> silent exe "!echo \"" .<somehow access @@> . "\"> /dev/clipboard"

silent exe "!echo \"".(@")."\"> /dev/clipboard"

Note that you still have command injection issues here, where, if
the contents of the register have shell metacharacters in it
(with double-quotes, dollar-signs can access variables, the "!"
can end up with shell expansion, and a literal
backslash-doublequote in your register will prematurely close the
string with odd results), or if you change to using
single-quotes, you mostly only have to concern yourself with
single-quotes in the register contents.

Alternatively, you might be able to do something like

call writefile([@"], '/dev/clipboard')

or

echo writefile([@"], '/dev/clipboard')?"Failed":"Succeeded"

which should write the contents with less opportunity for
escaping issues.

-tim

Taylor Hedberg

unread,
Apr 18, 2012, 9:59:01 AM4/18/12
to vim...@googlegroups.com
Chris Sutcliffe, Wed 2012-04-18 @ 09:11:49-0400:

> Hi All,
>
> I'm trying to figure out a way to dump the contents of the '@@'
> registry (i.e. the registry populated by the yank command) to the
> /dev/clipboard device in Cygwin. Basically I'm trying:
>
> silent exe "!echo \"" . <somehow access @@ > . "\" > /dev/clipboard"
>
> But I can't figure out how to access @@. Simply trying:
>
> silent exe "!echo \"" . @@ . "\" > /dev/clipboard"
>
> Didn't work.
>
> Any help would be greatly apprecaited, thank you!
>
> Chris

The default register is ", not @. There is no @ register, as far as I am
aware.

silent execute '!echo "' . @" . '" >/dev/clipboard'

John Beckett

unread,
Apr 18, 2012, 6:25:28 PM4/18/12
to vim...@googlegroups.com
Tim Chase wrote:
> You're awfully close, but I think you're reaching for the
> wrong register.

No, @@ is another name for @" (see ':help @r'). Using " can
cause issues in some circumstances since it starts a comment.
It's easy to try this. Yank a couple of words then:
:echo @@

The following writes @@ (that is, @") to /dev/clipboard:
:call writefile(split(@@, "\n"), '/dev/clipboard')

However, what the OP should do is build Vim with clipboard
support (using :version should show "+clipboard").

John

Chris Sutcliffe

unread,
Apr 18, 2012, 10:47:04 PM4/18/12
to vim...@googlegroups.com
Thank you everyone for the help!

On 18 April 2012 18:25, John Beckett wrote:
> The following writes @@ (that is, @") to /dev/clipboard:
>   :call writefile(split(@@, "\n"), '/dev/clipboard')

Works like a charm.

> However, what the OP should do is build Vim with clipboard
> support (using :version should show "+clipboard").

Unfortunately the "+clipboard" for Cygwin uses the X-Windows
clipboard, not the native Windows clipboard. In this case
/dev/clipboard is a way to access the native Windows clipboard within
Cygwin. It has the benefit of understanding utf-8 which
putclip/getclip currently do not.

Thank you for the tip!

John Beckett

unread,
Apr 19, 2012, 1:00:36 AM4/19/12
to vim...@googlegroups.com
Chris Sutcliffe wrote:
>> The following writes @@ (that is, @") to /dev/clipboard:
>>   :call writefile(split(@@, "\n"), '/dev/clipboard')
>
> Works like a charm.
>
>> However, what the OP should do is build Vim with clipboard support
>> (using :version should show "+clipboard").
>
> Unfortunately the "+clipboard" for Cygwin uses the X-Windows
> clipboard, not the native Windows clipboard. In this case
> /dev/clipboard is a way to access the native Windows
> clipboard within Cygwin. It has the benefit of understanding
> utf-8 which putclip/getclip currently do not.

Thanks for info, but the code is going to cost you!

We have this tip:
http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim

and it needs some cleaning. Editing the wiki would be best, but
if that does not appeal, please tell me what needs to be done.

Is there anything there that should be deleted as a duplicate or
obsolete or misguided? I guess you are saying the stuff which
uses putclip needs at least a disclaimer that it fouls up utf-8?

Should my writefile line above be added? Where in the tip: first
as best procedure with current software, or last as an
alternative?

Can readfile be used to do a paste? Like one of:

:let @@ = join(readfile('/dev/clipboard'), "\n")

:put =join(readfile('/dev/clipboard'), "\n")

Does anyone know why the quotes ("\n") are a comment with :put?
How can it be told to work like it should? I have previously
noticed that it truncates the command at the first quote.

There should be more: I think appending "\n" if more than one
line was read (to make it a linewise paste ... I think).

John

Gary Johnson

unread,
Apr 19, 2012, 2:10:22 AM4/19/12
to vim...@googlegroups.com
On 2012-04-18, Chris Sutcliffe wrote:
> Thank you everyone for the help!
>
> On 18 April 2012 18:25, John Beckett wrote:
> > The following writes @@ (that is, @") to /dev/clipboard:
> > � :call writefile(split(@@, "\n"), '/dev/clipboard')
>
> Works like a charm.
>
> > However, what the OP should do is build Vim with clipboard
> > support (using :version should show "+clipboard").
>
> Unfortunately the "+clipboard" for Cygwin uses the X-Windows
> clipboard, not the native Windows clipboard. In this case
> /dev/clipboard is a way to access the native Windows clipboard within
> Cygwin. It has the benefit of understanding utf-8 which
> putclip/getclip currently do not.

Does anyone know what ever happened to the vim_cygwin_clip_patch?
It let Vim for Cygwin use the Windows clipboard. It was originally
posted to the vim-dev list by Frodak Baksik in February, 2007.
Resurrecting or redeveloping that is probably the right way to fix
this issue.

Regards,
Gary

Christian Brabandt

unread,
Apr 19, 2012, 2:32:22 AM4/19/12
to vim...@googlegroups.com

I think I have the patch floating around here somewhere and in any
case it should still be available at [1].
Last time I tried patching on Cygwin using the simple patch[2], I
couldn't link the binary. But I haven't had time to investigate the
issue in detail, as I only seldomly have access to a Windows
development system.

[1])http://vim.1045645.n5.nabble.com/Re-Subject-Re-vim-on-cygwin-using-win32-clipboard-td1208486.html
[2])http://groups.google.com/group/vim_use/msg/d32c24ffffd503b1

regards,
Christian

Chris Sutcliffe

unread,
Apr 19, 2012, 2:40:37 AM4/19/12
to vim...@googlegroups.com
Hi John,

On 19 April 2012 01:00, John Beckett wrote:
> Thanks for info, but the code is going to cost you!
>
> We have this tip:
> http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim
>
> and it needs some cleaning. Editing the wiki would be best, but
> if that does not appeal, please tell me what needs to be done.

I guess since I'm the original author of the tip, I should keep it up
to date. :)

> Is there anything there that should be deleted as a duplicate or
> obsolete or misguided? I guess you are saying the stuff which
> uses putclip needs at least a disclaimer that it fouls up utf-8?

I've updated the wiki commenting out the putclip / getclip lines and
adding a comment as to why. Given that the /dev/clipboard is a new
addition to Cygwin, I wanted to leave the putclip / getclip methods
there since they would need to be uses in earlier versions of Cygwin
(i.e. 1.6, etc.).

> Can readfile be used to do a paste? Like one of:
>
> :let @@ = join(readfile('/dev/clipboard'), "\n")

That also works very nicely, so I've added this to wiki tip as well.

Thank you again for the tips, as the utf-8 limitation of putclip /
getclip was really annoying.

Cheers!

Chris Sutcliffe

unread,
Apr 19, 2012, 2:48:12 AM4/19/12
to vim...@googlegroups.com
On 19 April 2012 02:10, Gary Johnson wrote:
> Does anyone know what ever happened to the vim_cygwin_clip_patch?
> It let Vim for Cygwin use the Windows clipboard.  It was originally
> posted to the vim-dev list by Frodak Baksik in February, 2007.

I believe it is suffering from bitrot, especially given the changes to
the clipboard handling with the recent version of Cygwin.

> Resurrecting or redeveloping that is probably the right way to fix
> this issue.

Previously I would have agreed, however, recently I've started to use
the Cygwin X-Windows environment, in which it is nice to have the
clipboard integration with it as well as having the flexibility of
integrating with the native Windows clipboard via the tip John
mentioned.

Cheers,

John Beckett

unread,
Apr 19, 2012, 3:15:13 AM4/19/12
to vim...@googlegroups.com
Chris Sutcliffe wrote:
> I guess since I'm the original author of the tip, I should
> keep it up to date. :)

Oh! Thanks for the update, and for crediting me. Another way of
doing that is to put a brief mention in the edit summary,
because it's not really possible to credit people in tips as
just about everyone gets their ideas from somewhere else.

I have just remembered that :put works with a list, so you might
like to consider the following as well (for paste lines):

:put =readfile('/dev/clipboard')

John

Chris Sutcliffe

unread,
Apr 19, 2012, 3:31:23 AM4/19/12
to vim...@googlegroups.com
On 19 April 2012 03:15, John Beckett wrote:
> Oh! Thanks for the update, and for crediting me. Another way of
> doing that is to put a brief mention in the edit summary,
> because it's not really possible to credit people in tips as
> just about everyone gets their ideas from somewhere else.

Fair enough, I'll keep that in mind going forward,

> I have just remembered that :put works with a list, so you might
> like to consider the following as well (for paste lines):
>
> :put =readfile('/dev/clipboard')

The behaviour is slightly different. using the 'let' command and
'normal p' the cursor remains at it's original position, whereas with
the 'put' command, the cursor is moved to the last line.
Additionally, the 'put' command is linewise, so the contents of the
clipboard is always dumped on the line below where the cursor was
originally.

Cheers,

Reply all
Reply to author
Forward
0 new messages