Skip to content

Instantly share code, notes, and snippets.

@mawaldne
Last active December 5, 2015 18:56
Show Gist options
  • Save mawaldne/b47337f05446f17a9cbf to your computer and use it in GitHub Desktop.
Save mawaldne/b47337f05446f17a9cbf to your computer and use it in GitHub Desktop.
Vim - Automatically yank to system clipboard from Visual mode
Yank normally, but just copy it automatically to your system clipboard as well.
Added to my .vimrc. Should work from visual mode when you press y and from ex mode: 1,10YankToSystemRegister
" Auto Yank text to the OS X clipboard
function! CopyToSystemRegister()
let @*=@"
endfunction
command! -range -bar YankToSystemRegister <line1>,<line2>yank|call CopyToSystemRegister()
vnoremap y :YankToSystemRegister<cr>
@mawaldne
Copy link
Author

mawaldne commented Dec 5, 2015

hmmm, one problem with this is now regular registers dont work. "ay, content isnt in the A register. Wonder if theres a way to get the current selected register?

@mawaldne
Copy link
Author

mawaldne commented Dec 5, 2015

set clipboard=unnamed is probably as good as it gets. Im not a fan of having everything characters go to the system clipboard though but vim registers still work fine.

@mawaldne
Copy link
Author

mawaldne commented Dec 5, 2015

Also started using yankring.vim which is awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment