Vim Tips Wiki
Register
Advertisement
Tip 687 Printable Monobook Previous Next

created March 27, 2004 · complexity basic · author Khairulmizam Samsudin · version 5.7


As of my knowledge there is no clipboard register for Mac OS X unlike Windows (VimTip21). However you can use pbcopy/pbpaste command to achieve the same thing.

Example

:.!pbcopy "Copy current line clipboard
:4,8!pbcopy "Copy line 4 to 8
:!echo "%:p" | pbcopy "Copy current filename to clipboard
:r !pbpaste "Paste clipboard content to current line

References

Comments

I find that the + register works for transferring back and forth to the OS X clipboard.


Sorry I fail to mention that i compile vim with `--without-x --disable-gui` therefore I dont have access to the unnamed registers. pbcopy/pbpaste is a work around for it


I use 4,8w !pbcopy - which prevents the deletion of lines within the window-file where i run the command


I've got the following lines in my .vimrc:

map <F2> :.w !pbcopy<CR><CR>
map <F3> :r !pbpaste<CR>

Pressing <F2> copies the current line to the clipboard, pressing <F3> pastes the current content from the clipboard.


My maps just add onto what these guys have worked on.

<F1> pastes, but I have it configured so it works very well in insert mode and in normal mode. The nopaste setting makes sure that auto-indent doesn't go crazy when you try to paste something in.

<F2> copies text. If you are in normal mode, it will just grab the line your working on. If you in visual mode however, it will grab all the selected text.

nmap <F1> :set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
imap <F1> <ESC>:set paste<CR>:r !pbpaste<CR>:set nopaste<CR>

nmap <F2> :.w !pbcopy<CR><CR>
vmap <F2> :w !pbcopy<CR><CR>

Advertisement