Vim Tips Wiki
No edit summary
(21 intermediate revisions by 13 users not shown)
Line 1: Line 1:
  +
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=687
 
|id=687
 
|previous=686
 
|previous=686
 
|next=688
 
|next=688
|created=March 27, 2004
+
|created=2004
 
|complexity=basic
 
|complexity=basic
 
|author=Khairulmizam Samsudin
 
|author=Khairulmizam Samsudin
 
|version=5.7
 
|version=5.7
 
|rating=276/77
 
|rating=276/77
  +
|category1=Mac OS X
  +
|category2=
 
}}
 
}}
  +
 
As of my knowledge there is no clipboard register for Mac OS X unlike Windows ([[VimTip21]]). However you can use pbcopy/pbpaste command to achieve the same thing.
 
As of my knowledge there is no clipboard register for Mac OS X unlike Windows ([[VimTip21]]). However you can use pbcopy/pbpaste command to achieve the same thing.
   
Example
+
Example:
 
 
<pre>
 
<pre>
 
:.!pbcopy "Copy current line clipboard
 
:.!pbcopy "Copy current line clipboard
Line 25: Line 27:
   
 
==Comments==
 
==Comments==
  +
For [http://code.google.com/p/macvim/ MacVim] and Windows Gvim, I have the following in my ~/.vimrc:
I find that the + register works for transferring back and forth to the OS X clipboard.
 
  +
<pre>
  +
set clipboard=unnamed
  +
</pre>
   
  +
Operations such as <code>yy</code>, <code>D</code>, and <code>P</code> work with the system clipboard. No need to prefix them with <code>"+</code> or <code>"*</code>.
 
----
 
----
 
I find that the <code>+</code> register works for transferring back and forth to the OS X clipboard.
Sorry I fail to mention that i compile vim with `--without-x --disable-gui` therefore I dont have access to the unnamed registers. pbcopy/pbpaste is a work around for it
 
   
 
----
 
----
 
I failed to mention that I compile Vim with '--without-x --disable-gui' therefore I don't have access to the unnamed registers. pbcopy/pbpaste is a work around.
I use 4,8w !pbcopy - which prevents the deletion of lines within the window-file where i run the command
 
   
 
----
 
----
 
I use <code>4,8w !pbcopy</code> which prevents the deletion of lines within the window-file where I run the command.
I've got the following lines in my .vimrc:
 
   
  +
----
 
I've got the following lines in my .vimrc:
 
<pre>
 
<pre>
map &lt;F2&gt; :.w !pbcopy&lt;CR&gt;&lt;CR&gt;
+
map <F2> :.w !pbcopy<CR><CR>
map &lt;F3&gt; :r !pbpaste&lt;CR&gt;
+
map <F3> :r !pbpaste<CR>
 
</pre>
 
</pre>
   
Pressing &lt;F2&gt; copies the current line to the clipboard, pressing &lt;F3&gt; pastes the current content from the clipboard.
+
Pressing <F2> copies the current line to the clipboard, pressing <F3> pastes the current content from the clipboard.
   
 
----
 
----
My maps just add onto what these guys have worked on.<br><br>
+
My maps just add onto what these guys have worked on.
<F1> pastes, but I have it configured so it works very well in insert mode and in normal mode. The nopaste setting makes sure that auto-indent doesn't go crazy when you try to paste something in.
+
*<F1> pastes, but I have it configured so it works very well in insert mode and in normal mode. The nopaste setting makes sure that auto-indent doesn't go crazy when you try to paste something in.
 
*<F2> copies text. If you are in normal mode, it will just grab the line your working on. If you in visual mode however, it will grab all the selected text.
<br><br>
 
<F2> copies text. If you are in normal mode, it will just grab the line your working on. If you in visual mode however, it will grab all the selected text.
 
 
<pre>
 
<pre>
 
nmap <F1> :set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
 
nmap <F1> :set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
imap <F1> <ESC>:set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
+
imap <F1> <Esc>:set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
 
 
nmap <F2> :.w !pbcopy<CR><CR>
 
nmap <F2> :.w !pbcopy<CR><CR>
 
vmap <F2> :w !pbcopy<CR><CR>
 
vmap <F2> :w !pbcopy<CR><CR>
 
</pre>
 
</pre>
  +
  +
Comment: the nmap commands work perfectly, but unfortunately the vmap-copy doesn't (it grabs the whole line instead of the selected text). I'm working with the non-GUI version on Mac OS X. Later I will try to figure out a workaround.
  +
----
  +
Use {{script|id=2098|text=fakeclip}} pseudo clipboard register for non-GUI version of Vim on Cygwin and Mac OS X
  +
  +
----
  +
It looks like there's a problem with fakeclip on Mac OS X (I don't know which versions are affected). For everyone who gets "Platform not supported: Unknown" or something like this should try this:
  +
  +
In <code>autoload/fakeclip.vim</code>: Search for <code>system('uname -o')</code> and change it to <code>system('uname')</code>. Now it should work.
  +
  +
----
  +
Another tip: For cross-platform clipboard sharing you can use the open-source (GPL) [http://clipboardmshare.steweche.co.uk/ ClipboardMultiSharer] with text and image data on any platform that runs Java; in particular, Mac OS X, Windows and Linux.
  +
  +
----
  +
Since version 7.3 the console version of Vim supports Mac OS X clipboard. As noted above just add the following to ~/.vimrc
  +
<pre>
  +
set clipboard=unnamed
  +
</pre>
  +
  +
----
  +
As of Mountain Lion, the previous tip does not appear to work in system-provided vim; yanked lines do not go into the system clipboard, nor does anything yanked to the * or + registers.
  +
  +
It does however work with MacVim in terminal mode.
  +
  +
----
  +
Also on Lion
  +
<pre>
  +
set clipboard=unnamed
  +
</pre>
  +
no longer works but pbcopy and pbpaste still do. Tip is still valid.
   
 
----
 
----
[[Category:Mac OS X]]
 

Revision as of 08:06, 9 February 2013

Tip 687 Printable Monobook Previous Next

created 2004 · complexity basic · author Khairulmizam Samsudin · version 5.7


As of my knowledge there is no clipboard register for Mac OS X unlike Windows (VimTip21). However you can use pbcopy/pbpaste command to achieve the same thing.

Example:

:.!pbcopy "Copy current line clipboard
:4,8!pbcopy "Copy line 4 to 8
:!echo "%:p" | pbcopy "Copy current filename to clipboard
:r !pbpaste "Paste clipboard content to current line

References

Comments

For MacVim and Windows Gvim, I have the following in my ~/.vimrc:

set clipboard=unnamed

Operations such as yy, D, and P work with the system clipboard. No need to prefix them with "+ or "*.


I find that the + register works for transferring back and forth to the OS X clipboard.


I failed to mention that I compile Vim with '--without-x --disable-gui' therefore I don't have access to the unnamed registers. pbcopy/pbpaste is a work around.


I use 4,8w !pbcopy which prevents the deletion of lines within the window-file where I run the command.


I've got the following lines in my .vimrc:

map <F2> :.w !pbcopy<CR><CR>
map <F3> :r !pbpaste<CR>

Pressing <F2> copies the current line to the clipboard, pressing <F3> pastes the current content from the clipboard.


My maps just add onto what these guys have worked on.

  • <F1> pastes, but I have it configured so it works very well in insert mode and in normal mode. The nopaste setting makes sure that auto-indent doesn't go crazy when you try to paste something in.
  • <F2> copies text. If you are in normal mode, it will just grab the line your working on. If you in visual mode however, it will grab all the selected text.
nmap <F1> :set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
imap <F1> <Esc>:set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
nmap <F2> :.w !pbcopy<CR><CR>
vmap <F2> :w !pbcopy<CR><CR>

Comment: the nmap commands work perfectly, but unfortunately the vmap-copy doesn't (it grabs the whole line instead of the selected text). I'm working with the non-GUI version on Mac OS X. Later I will try to figure out a workaround.


Use fakeclip pseudo clipboard register for non-GUI version of Vim on Cygwin and Mac OS X


It looks like there's a problem with fakeclip on Mac OS X (I don't know which versions are affected). For everyone who gets "Platform not supported: Unknown" or something like this should try this:

In autoload/fakeclip.vim: Search for system('uname -o') and change it to system('uname'). Now it should work.


Another tip: For cross-platform clipboard sharing you can use the open-source (GPL) ClipboardMultiSharer with text and image data on any platform that runs Java; in particular, Mac OS X, Windows and Linux.


Since version 7.3 the console version of Vim supports Mac OS X clipboard. As noted above just add the following to ~/.vimrc

set clipboard=unnamed

As of Mountain Lion, the previous tip does not appear to work in system-provided vim; yanked lines do not go into the system clipboard, nor does anything yanked to the * or + registers.

It does however work with MacVim in terminal mode.


Also on Lion

set clipboard=unnamed

no longer works but pbcopy and pbpaste still do. Tip is still valid.