Vim Tips Wiki
(Undo revision 29080 by 74.118.195.117 (talk) Vandalism)
(car car income income loan loan low low 493)
Line 1: Line 1:
  +
25459.....94597
{{TipNew
 
  +
25459.....94597
|id=1511
 
|previous=1510
 
|next=1512
 
|created=July 23, 2007
 
|complexity=basic
 
|author=Robert Iannucci
 
|version=7.0
 
|subpage=/200712
 
|category1=Integration
 
|category2=Mac OS X
 
}}
 
{{dodgy|this tip (probably) applies to a very specific system, which is not made obvious. Most Vim users can use the built-in methods of [[Accessing the system clipboard]] with no trouble}}
 
I know that this has been covered in [[VimTip687|other]] [[VimTip984|places]], but I was dissatisfied with the ability to only copy and paste line-wise. I found it particularly annoying when I just wanted to yank a single word out to do a web search or similar. After a bit of poking around with Vim's builtin functions (on version 7 at least), I discovered the following workaround:
 
 
<pre>
 
" On OSX
 
vmap <C-c> y:call system("pbcopy", getreg("\""))<CR>
 
nmap <C-v> :call setreg("\"",system("pbpaste"))<CR>p
 
</pre>
 
 
<pre>
 
" On ubuntu (running Vim in gnome-terminal)
 
" The reason for the double-command on <C-c> is due to some weirdness with the X clipboard system.
 
vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>
 
nmap <C-v> :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p
 
</pre>
 
But the double command problem seems to be caused by the xclip utility. That bug is present in xclip 0.08-7. But xclip 0.11 downloaded from sourceforge works fine and:
 
<pre>
 
vmap <C-c> y: call system("xclip -i -selection clipboard", getreg("\""))<CR>
 
</pre>
 
is sufficient.
 
 
<!-- Space indent (not pre) so help template works. -->
 
" groovyness in Insert mode (lets you paste and keep on typing)
 
" This blows away i_CTRL-V though (see {{help|i_CTRL-V}})
 
imap <C-v> <Esc><C-v>a
 
 
"+ and "* are supposed to 'do the right thing', but there isn't any such integration with OS X, and I have simply had complete failure with ubuntu (even with +xterm_clipboard +clipboard +X11).
 
 
Though, it has been reported to work fine on Ubuntu 8.04 with default packages (vim 7.1-138).
 
 
One other thing to note: mapping <C-v> blows away the whole visual block mode, but I never use it. A possible alternative mapping would be to map these with something like ':vnoremap y' so that it's automatic in visual mode.
 
 
==Comments==
 
{{Todo}}
 
*Explain the point of this tip. Why is it necessary to avoid using the copy/paste mechanisms provided by Vim?
 
*Is this tip ''only'' related to Mac OS X or the Ubuntu Linux? If so, state that at the top.
 
*Is there some problem with Vim (what version?) on Mac OS X? Exactly what? Has the appropriate mailing list been informed?
 
*Do other users experience this problem? If not, should the tip be flagged for deletion?
 
*[[VimTip1199]] claims to be related to character-wise pasting. Is it helpful?
 
 
To address the first question, the point of mapping <C-c> is to be able to copy large blocks of text from vim into another application. I use this to copy from vim into an rdesktop session, for example.
 
:But my point in the above "todo" is that the tip needs to read coherently for people who might not be familiar with the particular problem that the tip addresses. For example, Vim is run by a lot of Windows users, where the idea of having trouble copying between apps is totally unknown. The text in the tip only makes sense to people who are used to having the problem.
 
:Also, you might use <C-c> to copy large blocks of text, but the author of the tip explicitly talks about yanking a single word. The text should make sense: Is the tip only for short snippets? Do all Mac OS X users need this tip to copy between apps? What about Ubuntu users?
 
:Vim has <tt>"+y</tt> and <tt>"+p</tt>. The tip needs to explain when that is not adequate.
 
:If anyone has some suggestions, please edit the tip, or add suggested text below. In time, suggestions could be enhanced and merged into the tip. --[[User:JohnBeckett|JohnBeckett]] 03:34, 11 November 2008 (UTC)
 
 
 
:The very page referenced by the dodgy section notes that the builtin mechanism doesn't work with OS X...
 
----
 

Revision as of 13:15, 15 January 2011

25459.....94597 25459.....94597