Skip to content

Instantly share code, notes, and snippets.

@gobenji
Last active December 15, 2015 20:08
Show Gist options
  • Save gobenji/5316003 to your computer and use it in GitHub Desktop.
Save gobenji/5316003 to your computer and use it in GitHub Desktop.
Paste the content of tmux buffers within vim without having to put vim into Paste mode
function TmuxPaste(buffer)
if ! a:buffer
let buffer = "0"
else
let buffer = a:buffer
endif
let tmpfile = tempname()
let cmd = printf("tmux save-buffer -b %s %s", shellescape(buffer), shellescape(tmpfile))
let output = system(cmd)
if v:shell_error != 0
let msg = printf("Error running '%s': %s", cmd, output)
echohl WarningMsg | echon msg | echohl None
return
endif
let lines = readfile(tmpfile)
call delete(tmpfile)
let cursor = getpos(".")
let cursor[1] += 1
call append(line("."), lines)
call setpos('.', cursor)
endfunction
function ListTmuxBuffers(ArgLead, CmdLine, CursorPos)
return system("tmux list-buffers | cut -d: -f1")
endfunction
command -nargs=? -complete=custom,ListTmuxBuffers Paste call TmuxPaste(<q-args>)
@gobenji
Copy link
Author

gobenji commented Apr 5, 2013

add it to .vimrc

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