Reputation: 527
Since vim doesn't support native clipboard on OS X by default, I decided to create some keybindings to emulate it.
I started with such a command, which passes visual selection to pbcopy and replaces selection with command output. Since it has no output and just deletes text, i immediately undo the change.
:vmap c !pbcopy<CR> :undo<CR>
It works fine, but not if I'm copying the last line in the file. It is copied well, but undo doesn't bring it back. If I manually undo later, it works fine.
Is there a way to make this binding work with on the last line as well?
Upvotes: 1
Views: 733
Reputation: 872
Nothing wrong with setting a keybinding, but I've never felt the need to.
As with all platforms, Vim does save to the system clipboard, but only when using the visual commands. Select using any of the visual commands (V, shift-V, Control-V). Then yank. Whatever was visually selected will be on the system clipboard.
Upvotes: 0
Reputation: 196886
Remove the space between the first <CR>
and :undo
:
:vmap c !pbcopy<CR>:undo<CR>
Upvotes: 2