Use the system clipboard in vim instead of vim's clipboard

1

2

Is there any way to use the system clipboard on Mac OS X (it is accessible with pbpaste and pbcopy to read and write, respectively) in place of vim's clipboard? So, for instance, when I did a cut or copy in vim, it would go to the system clipboard. And, also, if I copied something to the system clipboard, I could paste it into vim with P or p

Thanks in advance!

Wuffers

Posted 2010-10-17T19:39:51.940

Reputation: 16 645

Answers

4

Vim 7.3 added “clipboard support in the Mac console” (see under :help added-7.3). The standard * register is the system clipboard when running a tty-based instance of vim (+ also works and is an alias for * like most non-X11 systems). I am using Vim 7.3 from MacPorts.

Paste: "*p
Copy 4 lines: "*4yy
Cut 4 lines: "*4dd

For Vim 7 versions before 7.3, you can use fakeclip.

Chris Johnsen

Posted 2010-10-17T19:39:51.940

Reputation: 31 786

This works perfectly, thanks! But, is there any way to map it to a different shortcut? – Wuffers – 2010-10-17T21:43:14.710

You could map then to pretty much anything you want with various map commands. F1 as Paste: :map! <F1> "*p F2 as Copy: :map! <F2> "*y (press F2 then a motion command, or press F2 with a visual selection active). With the support built into Vim 7.3 you can also :set clipboard=unnamed so that normal yank, delete, change, and put operations (i.e. those done without a " + register character prefix) go through the system clipboard. – Chris Johnsen – 2010-10-18T02:47:19.850