Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created September 3, 2012 03:36
Show Gist options
  • Save saitoha/3606583 to your computer and use it in GitHub Desktop.
Save saitoha/3606583 to your computer and use it in GitHub Desktop.
iTerm2 Remote Clipboard Copy
function! s:ITerm2Copy() range
let l:tmp = @@
silent normal gvy
let l:selected = @@
let l:i = 0
let l:len = strlen(l:selected)
let l:escaped = ''
while l:i < l:len
let l:c = strpart(l:selected, l:i, 1)
let l:escaped .= printf("\\u%04x", char2nr(l:c))
let l:i = l:i + 1
endwhile
let l:start = '\x1b]50;CopyToClipboard=\x07'
let l:end = '\x1b]50;EndCopy\x07'
call system('echo -en "' . l:start . l:escaped . l:end . '" > /dev/tty')
redraw!
endfunction
command! -range ITerm2Copy :call s:ITerm2Copy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment