Skip to content

Instantly share code, notes, and snippets.

@zuloo
Created June 28, 2015 23:05
Show Gist options
  • Save zuloo/ee3d4560c29af51224c6 to your computer and use it in GitHub Desktop.
Save zuloo/ee3d4560c29af51224c6 to your computer and use it in GitHub Desktop.
Vim: copy to X clipboard
" pipe range as a shellescaped string to the vimclip shell script
function Xclip() range
echo system('echo '.shellescape(join(getline(a:firstline, a:lastline), '\n')).'| ~/bin/vimclip')
endfunction
" bind Ctrl-c and Ctrl-Shift-c to copy
vmap <C-c> :call Xclip()<CR>
vmap <C-C> :call Xclip()<CR>
#!/bin/sh
# export the DISPLAY, its not set when vim calls the script
export DISPLAY=:0.0
# this line allows you to also copy the content of complete files to your
# X clipboard by calling this script with
# vimclip FILENAME
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
# this pipes the input/file to X default clipboard
cat $input | xclip -selection c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment