Issue:
I often need to copy and paste text between X11 windows (e.g., xterm, vim) and native Mac OS windows (e.g., Terminal, Safari). This often results in undesirable results. How do I successfully (and reliably) copy and paste between these different flavors of windows?
Solution:
Follow the instructions below to copy from one flavor of window and paste into another. Note that vim and other X11 windows behave differently, but all Mac OS windows behave like Terminal. Some of these instructions require that you have click-through enabled in X11 and all of them assume that you are using a three-button mouse or the corresponding keyboard equivalents for a single-button mouse. The latter, in turn, requires that in the Input panel of the X11 preferences (see below), you have selected “Emulate three button mouse” and “Enable key equivalents under X11”.
- vim (X11) to xterm (X11): Select text in vim window using left mouse button; press Ctrl-C to copy; move cursor to xterm window; middle-click to paste.
- xterm (X11) to vim (X11): Select text in xterm window using left mouse button to copy; move cursor to vim window; press i, I, a, or A to enter vim's editing mode; middle-click to paste.
- xterm (X11) to Terminal (Mac OS): Select text in xterm window using left mouse button; press Cmd-C to copy; move cursor to Terminal window and left-click to raise it; press Cmd-V to paste.
- Terminal (Mac OS) to xterm (X11): Select text in Terminal window using left mouse button; press Cmd-C to copy; move cursor to xterm window and left-click to raise it; middle-click to paste.
- vim (X11) to Terminal (Mac OS): This one is tricky! Select text in vim window using left mouse button; press Ctrl-C to copy into vim's buffer; immediately press Cmd-C to copy vim's buffer into the X11 buffer; move cursor to the Terminal window and left-click to raise it; press Cmd-V to paste.
- Terminal (Mac OS) to vim (X11): Select text in Terminal window using left mouse button; press Cmd-C to copy; move cursor to vim window and left-click to raise it; press i, I, a, or A to enter vim's editing mode; middle-click to paste.
Note added on 14 Oct 2010:
The behavior described above has been tested and verified on a Mac Mini (Oct 2009 model), iMac 27-inch (Oct 2009 model), MacBook Air (Oct 2008 model), and MacBook Pro 13-inch (Jun 2009 model). One person with a recent (Apr 2010 model) MacBook Pro 15-inch has reported difficulty reproducing this behavior (specifically, failure of middle-click to paste). This failure mode is not present on the slightly older (Jun 2009 model) MacBook Pro 13-inch (i.e., copy/paste works as described above). Strangely, Cmd-C and Cmd-V work as copy and paste, respectively, within X11 on the newer MacBookPro, which is not the case on the other Mac models (despite the fact that all of them are using the same versions of X11 and OS X). I will test this on a different new model MacBook Pro as soon as possible.
Everything below here is somewhat obsolete and mainly refers to Leopard. The screen grabs of suggested X11 preference settings are still valid.
Note added on 29 Jun 2009: I've recently been helping someone who had just upgraded from Tiger to Leopard, and found that no matter what she did, Cmd-C in a Mac OS window would not paste into an X11 window. After a lot of experimenting, here is how I resolved her problem:
Method 1:
1) First, read all the way to the bottom of this configuration tip before you start this procedure, since there might be a better (or at least different) way to do it that will work for you. Snow Leopard users in particular should go all the way to the end of this section (03 Feb 2010 update), since most of the information presented here is applicable only to Leopard.
2) Quit X11 if it is running (Cmd-Q or select X11→Quit X11).
3) Open a Finder window and navigate to ~/Library/Preferences/. This is not the system-wide /Library folder, but the one in your user account home folder.
4) Double-click on org.x.X11.plist, which will open this X11 preferences file in the Property List Editor application.
5) You should see one line in the editor window that says
Root Dictionary 22 key/value pairs
6) Click on the small triangle to the left of the word Root to toggle open the parameter listing. Parameter values (in the Values column) can be changed by clicking on the corresponding up/down arrow icon on the right side of the Values column, then selecting from the available values in the resultant pop-up menu.
7) Ensure that all of the following parameters have values of “Yes”:
sync_clipboard_to_pasteboard
sync_pasteboard
sync_pasteboard_to_clipboard
sync_pasteboard_to_primary
sync_primary_on_select
wm_click_through
wm_ffm
The last two of these enable click-through and enable focus-follows-mouse in X11, respectively; the others enable synchronization between the various buffers that are used to store copied text.
Note added on 27 Jul 2009: The advice to set all of the parameters listed above to “Yes” is a brute force approach. I have not tested all possible parameter settings, so it is possible that not all of these parameters are required to produce the desired copy/paste behavior, and some parameters may have unintended (and possibly undesired) consequences for other programs. For example, M. Parry has informed me that after following the procedure described here, he started to get the following error when using LyX:
QClipboard::setData: Cannot set X11 selection owner for CLIPBOARD
and had severely reduced cut and paste functionality within Lyx itself. Setting sync_clipboard_to_pasteboard back to “No” resolved the problem with LyX and still preserved the desired copy/paste behavior between X11 and OS X windows.
8) Save the modified preferences file (Cmd-S or select File→Save).
9) Quit the Property List Editor (Cmd-Q or select File→Quit Property List Editor).
10) The next time X11 is started (e.g., by typing “xterm” on a Terminal window command line), the copy/paste behavior should conform to the descriptions listed above.
Update added on 09 Sep 2009:
A few people who have tried the procedure listed above (henceforth, “Method 1”) have reported to me that it did not work for them. I do not know for certain why, but I suspect it might have to do with what original version of X11 was installed on your computer and subsequently updated via Software Update, vs. starting fresh with a more recent version of X11 (e.g., if you have recently purchased a new Mac, or installed Leopard at a starting version of, say 10.5.5+) – see below for more information about this issue.
In any case, here is an alternate procedure (henceforth, “Method 2”), which seems to work if the above procedure does not. In fact, Method 2 is even better than Method 1, in the sense that it implements permanent easy access to the X11 copy/paste parameters without having to use the Property List Editor. Method 2 can even be applied on top of Method 1 with no apparent ill effects.
Method 2:
1) Start X11 (e.g., by typing “xterm” in an Apple Terminal window – remember, under Leopard, you should avoid starting X11 directly yourself, since it is started “on demand” by the OS).
2) Select Preferences under the X11 menu.
- If you have five tabs (Input, Output, Pasteboard, Windows, Security), then you are already set – go to the Pasteboard tab and click all of the boxes on. (As noted in Step 7 of Method 1, some experimentation regarding which of these boxes actually need to be clicked to obtain the desired copy/paste functionality may be required if you find that having all of them on interferes with the operation of a particular software title.)
Update added on 07 Oct 2009: After using X11 for a while now with the new preferences panels, I have found that deselecting the final option on the Pasteboard tab, “Update Pasteboard immediately...”, produces more reliable copy/paste results between OS X application windows and, for example, an X11 vim window. I have updated the screen grabs shown below to reflect this.
- If you only have three tabs (Input, Output, Security), then quit X11 and continue to the next step...
3) Install the X11 localization preferences for XQuartz 2.3.3.2, which I have made available here:
X11-Locales-2.3.3.2.dmg
Even if you are running the Apple standard X11 (which, as of OS X 10.5.8, is based on XQuartz 2.1.6), this will activate two new panels in your X11 preferences.
Note that I do not know of any way to UNDO this (short of reinstalling OS X), so use at your own risk!
4) Start over from Step 1 of Method 2...
To help illustrate Method 2, I have provided screen grabs of my X11 preferences settings after installing the X11 localization.
Update added on 23 Sep 2009:
The XQuartz project web site has this to say about the X11 localization fix described here (thanks to P. Chakka for notifying me about this):
“[OS X version] 10.5.7 updates the X11 server to match what shipped with [XQuartz X11 version] 2.3.2. Most of the userland, however, only saw security updates. The version reported by X11 in 10.5.7 is 2.1.6 to distinguish it from the 2.3.x series which contains a much newer userland. Users have reported some issues with the updated X11 in 10.5.7:
... Clipboard doesn't work after editing preferences → Install the localization updates that contain the clipboard preferences.”
XQuartz recommends installing the latest full XQuartz version of X11 to fix this problem (as they always recommend). However, I note (as described above in Method 2) that simply installing the localizations with Apple's X11 v2.1.6 activates the “missing” preferences panes, and fixes the copy/paste problem (or at least provides easy access to the associated preferences). In the past, I have generally recommended against installing the XQuartz X11 for most users, because it then requires manual reinstallation whenever Apple pushes out updates to their version of X11 through Software Update. However, with Leopard now presumably finalized, this is no longer an issue (barring unexpected future updates to the Leopard X11 from Apple).
Update added on 03 Feb 2010:
The Apple standard version of X11 distributed with Snow Leopard (10.6.2) is XQuartz version 2.3.4. Since it is a higher version than 2.3.3.2, it already contains the five Preferences tabs. Applying Method 1 or Method 2 is not necessary. Simply use the settings shown in the screen grabs above.
OS Version Compatibility: Lion, Snow Leopard, Leopard
Update Status: 03 December 2009
|