Last active
December 15, 2015 20:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add it to .vimrc