how to copy into system clipboard

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

how to copy into system clipboard

Li Xue
Hello,

Does anyone know how to copy text from vim into system clipboard? I am using iterm2 with the vim that comes with the Mac OS X system. 

I tried +y and tried *y, but still could not copy the text into the system clipboard.

Thanks.

Li

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Phil Dobbin
On 15/11/2013 09:54, Li Xue wrote:

> Hello,
>
> Does anyone know how to copy text from vim into system clipboard? I am
> using iterm2 with the vim that comes with the Mac OS X system.
>
> I tried +y and tried *y, but still could not copy the text into the
> system clipboard.

Try:

"*y

to yank to clipboard or, failing that, select what you want & use cmd-C.
MacVim respects Apple's HIG.

Cheers,

  Phil...

--
currently (ab)using
Arch Linux, CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Spherical
& That Damn Cat, OS X Snow Leopard & Tiger, Scientific Linux 6.4, Ubuntu
Quantal & Raring
GnuGPG Key : http://phildobbin.org/publickey.asc


--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Kyle Lippincott-2
I think this won't work, because the terminal vim has no method of communicating with the mac clipboard.  They're using the apple-provided vim, and also using a separate terminal app (so if there WAS some magic with Terminal.app + apple's vim, it's become less likely to work, but I don't think there is).




On Sat, Nov 16, 2013 at 1:35 AM, Phil Dobbin <[hidden email]> wrote:
On 15/11/2013 09:54, Li Xue wrote:

> Hello,
>
> Does anyone know how to copy text from vim into system clipboard? I am
> using iterm2 with the vim that comes with the Mac OS X system.
>
> I tried +y and tried *y, but still could not copy the text into the
> system clipboard.

Try:

"*y

to yank to clipboard or, failing that, select what you want & use cmd-C.
MacVim respects Apple's HIG.

Cheers,

  Phil...

--
currently (ab)using
Arch Linux, CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Spherical
& That Damn Cat, OS X Snow Leopard & Tiger, Scientific Linux 6.4, Ubuntu
Quantal & Raring
GnuGPG Key : http://phildobbin.org/publickey.asc


--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Phil Dobbin
On 16/11/2013 09:56, Kyle Lippincott wrote:

> I think this won't work, because the terminal vim has no method of
> communicating with the mac clipboard.  They're using the apple-provided
> vim, and also using a separate terminal app (so if there WAS some magic
> with Terminal.app + apple's vim, it's become less likely to work, but I
> don't think there is).

Selecting & Cmd-C works on my terminal Vim (iTerm2 & Vim 7.4.).

Also OP has posted this to MacVim & that has full clipboard integration
with the System clipboard so maybe installing MacVim is the way to go in
this particular instance.

Cheers,

  Phil...

--
currently (ab)using
Arch Linux, CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Spherical
& That Damn Cat, OS X Snow Leopard & Tiger, Scientific Linux 6.4, Ubuntu
Quantal & Raring
GnuGPG Key : http://phildobbin.org/publickey.asc


--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

how to copy into system clipboard

Bee
In reply to this post by Li Xue
The OP said 'I am using iterm2 with the vim that comes with the Mac OS X system'

To determine if that version of vim has access to the clipboard, type the following on the vim command line:

echo has("clipboard")

If it returned '0' then there is no clipboard support.

Bill

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Phil Dobbin
On 16/11/2013 16:07, Bee wrote:

> The OP said 'I am using iterm2 with the vim that comes with the Mac OS X system'
>
> To determine if that version of vim has access to the clipboard, type the following on the vim command line:
>
> echo has("clipboard")
>
> If it returned '0' then there is no clipboard support.

Apple's Vim on Snow Leopard is 7.2.108 which is ancient & is indeed
-clipboard. I use Mac Ports's terminal Vim: 7.4.52 which is +clipboard.

Best solution? Install MacVim: <https://code.google.com/p/macvim/> or
compile from source for terminal Vim from:
<http://www.vim.org/mercurial.php>.

Both come with +clipboard as default.

Cheers,

  Phil...

--
currently (ab)using
Arch Linux, CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Spherical
& That Damn Cat, OS X Snow Leopard & Tiger, Scientific Linux 6.4, Ubuntu
Quantal & Raring
GnuGPG Key : http://phildobbin.org/publickey.asc


--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Carl Jacobsen-3
In reply to this post by Li Xue
Indeed, the system vim has no clipboard support/access, and copying
with Cmd-C sometimes has trouble with line boundaries and certainly
can't deal with more than a screenful, so:

- Install and use the full GUI MacVim (it really is very nice), or,

- Install MacVim, then run "/Applications/MacVim.app/Contents/MacOS/Vim"
instead of "vim"; this will bring most of MacVim's goodness (including
clipboard access and more colors for syntax highlighting) to terminal
windows, or,

- write your selected text to the command "!pbcopy", which will put it
on the system clipboard (I've used This often when I find that I've
started something in the OS-supplied vim that I want to move over to
MacVim).

In the latter two cases, you can write shell commands or vim scripts
to make the change nearly transparent. 

Cheers,
Carl


On Nov 15, 2013, at 1:54 AM, Li Xue <[hidden email]> wrote:

Hello,

Does anyone know how to copy text from vim into system clipboard? I am using iterm2 with the vim that comes with the Mac OS X system. 

I tried +y and tried *y, but still could not copy the text into the system clipboard.

Thanks.

Li

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Ben Klein
In reply to this post by Kyle Lippincott-2
On Nov 16, 2013, at 3:56 AM, Kyle Lippincott <[hidden email]> wrote:

I think this won't work, because the terminal vim has no method of communicating with the mac clipboard.  They're using the apple-provided vim, and also using a separate terminal app (so if there WAS some magic with Terminal.app + apple's vim, it's become less likely to work, but I don't think there is).

I use the Apple-provided Vim on OS X with both Terminal and iTerm2. I have this in my ~/.vimrc:

" In visual mode, use Y to copy to system clipboard
vnoremap Y "*y

" In normal mode, do the same with the current line
nnoremap Y "*yy

So with a visual selection, I can use Y to copy to OS X’s clipboard (and without a selection, I can use it in normal mode to copy the current line likewise). I can confirm that it works -- I just opened my ~/.vimrc in Terminal and used Y to copy those lines so I could paste them here in Mail.

Ben

--
b

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Li Xue
In reply to this post by Carl Jacobsen-3
On Saturday, November 16, 2013 10:35:05 PM UTC+1, Carl Jacobsen wrote:

> Indeed, the system vim has no clipboard support/access, and copying
> with Cmd-C sometimes has trouble with line boundaries and certainly
> can't deal with more than a screenful, so:
>
>
> - Install and use the full GUI MacVim (it really is very nice), or,
>
>
>
> - Install MacVim, then run "/Applications/MacVim.app/Contents/MacOS/Vim"
> instead of "vim"; this will bring most of MacVim's goodness (including
> clipboard access and more colors for syntax highlighting) to terminal
> windows, or,
>
>
> - write your selected text to the command "!pbcopy", which will put it
> on the system clipboard (I've used This often when I find that I've
> started something in the OS-supplied vim that I want to move over to
> MacVim).
>
>
> In the latter two cases, you can write shell commands or vim scripts
> to make the change nearly transparent. 
>
>

Many thanks, Carl. It is very helpful!

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Colin Su
if someone want to access system clipboard without compiling VIM, you could try the plugin we wrote.



-- 
{
    greeting"Have a nice day!",
    name"Colin Su",
    nickname"LittleQ",
    email"[hidden email]",
    website"http://about.me/littleq",
    titles: [
        ["Organizer""Google Developer Group Taipei"]
        ["Tagtoo""Software Engineer"],
        ["CS@National Chengchi University""Student"]
    ]
}

On Monday, November 18, 2013 at 3:47 AM, Li Xue wrote:

On Saturday, November 16, 2013 10:35:05 PM UTC+1, Carl Jacobsen wrote:
Indeed, the system vim has no clipboard support/access, and copying
with Cmd-C sometimes has trouble with line boundaries and certainly
can't deal with more than a screenful, so:


- Install and use the full GUI MacVim (it really is very nice), or,



- Install MacVim, then run "/Applications/MacVim.app/Contents/MacOS/Vim"
instead of "vim"; this will bring most of MacVim's goodness (including
clipboard access and more colors for syntax highlighting) to terminal
windows, or,


- write your selected text to the command "!pbcopy", which will put it
on the system clipboard (I've used This often when I find that I've
started something in the OS-supplied vim that I want to move over to
MacVim).


In the latter two cases, you can write shell commands or vim scripts
to make the change nearly transparent. 

Many thanks, Carl. It is very helpful!

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Bee
In reply to this post by Carl Jacobsen-3
> write your selected text to the command "!pbcopy",
> will put it on the system clipboard

How do you 'write' selected text to "!pbcopy"?

Bill

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Carl Jacobsen-3
In reply to this post by Li Xue
On Nov 18, 2013, at 9:31 AM, Bee <[hidden email]> wrote:

>> write your selected text to the command "!pbcopy",
>> will put it on the system clipboard
>
> How do you 'write' selected text to "!pbcopy"?

The OS X command "pbcopy" reads from stdin, and puts whatever it gets
onto the system clipboard. How you use it depends on how you've
selected your text. To put the entire current buffer onto the
clipboard:

    :w !pbcopy

To put a range of lines onto the clipboard, use commands like:

    :5,10w !pbcopy
    :.,$w !pbcopy
    .'a,'bw !pbcopy
    :'<,'>w !pbcopy

You could also put something like this in your ~/.vimrc:

  nnoremap <silent> <Leader>c  :Copy<CR>
  vnoremap <silent> <Leader>c  :Copy<CR>

  command! -range Copy call DoCopy(<line1>, <line2>)

  func! DoCopy(sline, eline)
    exec ':' . a:sline . ',' . a:eline . 'w !pbcopy'
    redraw
    echohl ModeMsg
    echon "Copied lines " a:sline "-" a:eline " to system clipboard"
    echohl None
  endfunc

ought to let you use "\c" to copy the current line, or select some text
in Visual mode and use "\c" to select it, or simplify the lines in the
second example above to commands like:

    :5,10 Copy

Others here could probably improve the VimScript above; it's not my
native tongue.

Make sense?

Cheers,
Carl

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Bee
:help `<
'< `<  To the first line or character of the last selected Visual area in the current buffer.

I tried:
:`<,`>w !pbcopy

But got this error:
E492: Not an editor command: `<,`>w !pbcopy

Is `<,`> not a valid range?

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Colin Su
it should be ‘single quote’, so it’s 

‘<, ‘>

not 

`<, `>

-- 
{
    greeting"Have a nice day!",
    name"Colin Su",
    nickname"LittleQ",
    email"[hidden email]",
    website"http://about.me/littleq",
    titles: [
        ["Organizer""Google Developer Group Taipei"]
        ["Tagtoo""Software Engineer"],
        ["CS@National Chengchi University""Student"]
    ]
}

On Wednesday, November 20, 2013 at 10:07 AM, Bee wrote:

:help `<
'< `< To the first line or character of the last selected Visual area in the current buffer.

I tried:
:`<,`>w !pbcopy

But got this error:
E492: Not an editor command: `<,`>w !pbcopy

Is `<,`> not a valid range?

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Bee
On Wednesday, November 20, 2013 12:43:22 AM UTC-8, LittleQ wrote:
> it should be ‘single quote’, so it’s  ‘<, ‘> not  `<, `>

I know '< works for lines, but my attempt to use `< is to select a character range.

:help `<
'< `<  To the first line or character of the last selected Visual area in the current buffer.

Is there a way to write the CHARACTER selection to stdout? for use by pbcopy

Bill

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: how to copy into system clipboard

Tony Mechelynck
On Wednesday, November 20, 2013 6:44:11 PM UTC+1, Bee wrote:

> On Wednesday, November 20, 2013 12:43:22 AM UTC-8, LittleQ wrote:
>
> > it should be ‘single quote’, so it’s  ‘<, ‘> not  `<, `>
>
>
>
> I know '< works for lines, but my attempt to use `< is to select a character range.
>
>
>
> :help `<
>
> '< `<  To the first line or character of the last selected Visual area in the current buffer.
>
>
>
> Is there a way to write the CHARACTER selection to stdout? for use by pbcopy
>
>
>
> Bill

Ex-commands always act linewise on the range of lines you type between the : and the command name (or before the command name in a script).

To act on a visual selection you could type "+y in Visual mode, but using :normal would defeat this because hitting : in Visual mode goes out of Visual and places you in command-line mode with :'<,'> before the cursor, so that the ex-command you're about to type will act linewise on the just unselected Visual selection. You can act characterwise on an object or a motion by including the object or motion command after "+y in the operand of :normal, e.g.:

    :normal "+yW

will yank to the clipboard (i.e. "copy") the WORD at the cursor with no surrounding space. (Similarly, just :normal yW would yank it to the "unnamed" register.) Then you would have to find out how to put that out to your pbcopy command. One possibility (in a script) would be

    normal yW
    $put
    $,$w !pbcopy
    $del

remembering that the $put command will add the register linewise after the last line (thus creating a new line) so the $ line number in the last two commands above will be one more than in the $put command. I haven't checked where the cursor ends up at the end of this snippet.

The above snippet is valid because a WORD will never span more than one line. How to make it work for a multi-line characterwise yank is left as an exercise to the reader. (Hint: see "help line()" and ":help :execute")

Best regards,
Tony.
--
        As a general rule of thumb, never trust anybody who's been in therapy
for more than 15 percent of their life span.  The words "I am sorry" and "I
am wrong" will have totally disappeared from their vocabulary.  They will stab
you, shoot you, break things in your apartment, say horrible things to your
friends and family, and then justify this abhorrent behavior by saying:
"Sure, I put your dog in the microwave.  But I feel *better* for doing it."
                -- Bruce Feirstein, "Nice Guys Sleep Alone"

--
--
You received this message from the "vim_mac" 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 the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.