In line copy and paste to system Clipboard

Source: Internet
Author: User
Tags builtin perl script

    • On the Wiki
      • Wiki Activity
      • Random page
      • Videos
      • Photos
      • Chat
    • Community Portal
    • To do
ContributeWatchlistrandom pagerecent changesin Line copy and paste to system Clipboard
1,616pages on
This WIKI EditTalk0 Tip 1511Printable Monobook Previous Next

created 2007 · Complexity Basic author Robert Iannucci version 7.0

This tip applies to those Mac, Linux, and Windows users who is unable to access the System clipboard using the BUILTIN Co Py and paste mechanism that VIM provides. Note that most Vim users can use the built-in methods of accessing the system Clipboard with no trouble. If you had problems, first make sure your Vim was compiled with clipboard support. If you still has problems, or cannot get a Vim compiled with clipboard support for some reason, this tip can help provide A workaround.

This have been covered in other places, but it can is annoying to the only being able to copy and paste line-wise. It can be particularly annoying if you just want to yank a single word to do a web search or similar. Luckily, Vim can use external utilities on many systems to access the Clipboard with a system call:

"On Osxvmap <C-c> y:call system (" Pbcopy ", Getreg (" \ ")) <cr>nmap <C-v>: Call SetReg (" \ "", System (" Pbpaste ")) <cr>p
' On Ubuntu ' (Running Vim in gnome-terminal) ' The reason for the Double-command on <C-c> be due to some weirdness wit H The X clipboard system.vmap <C-c> y:call System ("Xclip-i-selection clipboard", Getreg ("\")) <cr>:call Syst EM ("Xclip-i", Getreg ("\")) <cr>nmap <C-v>: Call SetReg ("\" ", System (" Xclip-o-selection clipboard ") < Cr>p

But the double command problem seems to being caused by the Xclip utility. That bug was present in Xclip 0.08-7. But Xclip 0.11 downloaded from SourceForge works fine and:

Vmap <C-c> Y:call System ("Xclip-i-selection clipboard", Getreg ("\")) <CR>

is sufficient.

"Groovyness in Insert mode (lets-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" * is supposed to ' does the right thing ', but there isn ' t any such integration with OS X, and I had simply had comp Lete failure with Ubuntu (even with +xterm_clipboard +clipboard +x11).

Though, it had 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, and I never use it. A possible alternative mapping would is to map these with something like ': Vnoremap y ' so ' it's automatic in visual mo De.

This same problem have been observed not just on OS X, but also on Linux machines. Fortunately, if the "+ and" * buffers don ' t work, a-call can is made to the Xclip utility. The following maps ' CTRL + C ' to copy and ' Insert ' to paste (since Ctrl + V is used for Visual block mode in vim)

Vmap <C-c>:<esc> ' >a<cr><esc>mx ' <i<cr><esc>my ' xk$v ' y!xclip-selection C <cr>umap <Insert>: Set paste<cr>i<cr><cr><esc>k:.! Xclip-o<cr>jxkjx:set nopaste<cr>

The copy shortcut uses marks so rather than have the entire line copied, only the text selected in Visual mode is C Opied. Finally, an undo at the end of restores the text that would otherwise has been deleted. The paste shortcut switches to paste mode so it certain options like indenting is disabled, then switches back after PA Sting the text. Note the <CR> and J commands so, text can pasted in the middle of the line.

On Windows machines that has Cygwin support,/dev/clipboard can is used in place of Xclip to gain access to the Clipboard , should users find the "+ and" * Registers don ' t work.


To do

    • Explain the point of this tip. Why are 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 is 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 is flagged for deletion?
    • VIMTIP1199 claims to being related to character-wise pasting. Is it helpful?

To address the first question, the point of mapping <C-c> was to being able to copy large blocks of text from Vim into a nother application. I use the-to-copy from Vim into a rdesktop session, for example.

But my point in
the above "Todo" was that the tip of needs to read coherently for people who might not being familiar with The particular problem that the tip addresses. For example, Vim was run by a lot of Windows users, where the idea of the have trouble copying between apps is totally unknow N. The text in the tip is only makes sense to people who is used to have the the problem.
Also, might use <C-c> to copy large blocks of text, but the author of the tip explicitly talks about Yanki Ng a single word. The text should make Sense:is the tip is only for short snippets? Do any MAC OS X users need this tip to copy between apps? What is the Ubuntu users?
Vim has "+y and "+p . The tip needs to explain if that's not adequate.
If anyone have some suggestions, please edit the tip, or add suggested text below. In time, suggestions could is enhanced and merged into the tip. --johnbeckett 03:34, November (UTC)
It's not so one
wishes to avoid the builtin vim shortcuts. Rather, the "+ and" * is sometimes not integrated with the system Clipboard, and in those cases there needs to be some wo Rkaround so copy and paste are enabled between Vim and external applications. This problem have been observed on Windows machines as well as Linux (CentOS), and the problem seems to being there on Mac OS  X as well. --preceding Unsigned comment added by Radtad82 19:42,
The very page referenced by the dodgy sections notes that the BUILTIN mechanism doesn ' t work with OS X. --preceding Unsigned comment added by 04:33, August 6,
on a system where do I see a problem, please run Vim and enter  : version  and Note whether it Shows +clipboard (support for clipboard have been compiled to Vim), Or-clipboard (clipboard  not supported ). See :help +clipboard.
the "builtin mechanism doesn ' t work with OS X" are an old comment, and it probably refers to an obsolete tip. I don ' t use a Mac, but I asked Björn Winckler (who maintains Macvim), and both years ago he said that the Clipboard works W ith Vim on OS X ("The pasteboard are fully supported in both GUI and terminal mode ... The ' + ' and ' * ' registers is one and the same and by default you can use <D-x>/<D-c>/<D-v> to cut/copy/ Paste just like in any other Mac app "). I believe that all Vim in the last few years that have been compiled to support the Clipboard, would support it (although Ct Rl-c needs a mapping; I hope to cleanup these copy/paste tips and explain how to map ctrl-c etc without requiring other notepad-like features). I suspect this tip are a workaround for someone who are not using the correct version of vim. johnbeckett 10:53, M Ay (UTC)
Copied from talk page which'll be deletedEdit

This page was very useful for Linux. As far as I-know, this was only a issue in Linux, and possibly Mac OS x.

Copying out of terminal emulators on Linux is sometimes problematic. For example, I use a Perl script to send text (on highlight) via the ' Xsel ' program to the PRIMARY Clipboard in Rxvt-unico De. This Perl script, the However, does not function in the other applications, case at point, vim, when Vim was running in my URXVT VI Rtual terminal.

The solution suggested here allows me (and others) to select a block (or single word of text) and transfer it to another a Pplication, vim in a another terminal, web browser, anything. Vim ' s built in features only work for the same terminal window in which vim is already running. --mtkoan 23:16, April 9, UTC

In line copy and paste to system Clipboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.