abstract
| - This has been covered in other places, but it can be annoying to only be able to copy and paste line-wise. It can be particularly annoying when 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 OSX vmap y:call system("pbcopy", getreg("\"")) nmap :call setreg("\"",system("pbpaste"))p " On ubuntu (running Vim in gnome-terminal) " The reason for the double-command on is due to some weirdness with the X clipboard system. vmap y:call system("xclip -i -selection clipboard", getreg("\"")):call system("xclip -i", getreg("\"")) nmap :call setreg("\"",system("xclip -o -selection clipboard"))p 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: vmap y: call system("xclip -i -selection clipboard", getreg("\"")) is sufficient. " groovyness in Insert mode (lets you paste and keep on typing) " This blows away i_CTRL-V though (see [ help i_CTRL-V]) imap 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 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. This same problem has been observed not just on OS X, but also on Linux machines. Fortunately, if the "+ and "* buffers don't work, a call can be 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 :`>amx`my'xk$v'y!xclip -selection cu map :set pasteik:.!xclip -oJxkJx:set nopaste The copy shortcut uses marks so that rather than having the entire line copied, only the text selected in visual mode is copied. Finally, an undo at the end restores the text that would otherwise have been deleted. The paste shortcut switches to paste mode so that certain options like indenting are disabled, then switches back after pasting the text. Note the and J commands so that text can be pasted in the middle of the line. On Windows machines that have Cygwin support, /dev/clipboard can be used in place of xclip to gain access to the clipboard, should users find the "+ and "* registers don't work.
|