function! Screen_Send(text) if !exists("g:screen_sessionname") || !exists("g:screen_windowname") call Screen_Vars() endif let outfile = "/tmp/vim_buffer" let cmd = "screen -S " . g:screen_sessionname . " -p " . g:screen_windowname . " -X readbuf " . outfile exe system( cmd ) let cmd = "screen -S " . g:screen_sessionname . " -p " . g:screen_windowname . " -X paste . " exe system( cmd ) endfunction function! Screen_Select() let sess = g:screen_sessionname let win = g:screen_windowname let cmd = "screen -S " . sess . " -p " . win . " -X select " . win echo system(cmd) endfunction function! Screen_Session_Names(A,L,P) return system("screen -ls | awk '/Attached/ {print $1}'") endfunction function! Screen_Vars() if !exists("g:screen_sessionname") let g:screen_sessionname = input("session name: ", "", "custom,Screen_Session_Names") endif if !exists("g:screen_windowname") let g:screen_windowname = input("window name: ", g:screen_windowname) endif endfunction function! Screen_Exec(window) range if a:window != "" let g:screen_windowname = a:window endif exe writefile( getline(a:firstline, a:lastline), "/tmp/vim_buffer") let text = "" let i = a:firstline while i <= a:lastline let text = text . getline(i) . "\n" let i = i + 1 endwhile " XXX support cygwin weirdness if has("win32unix") echo text return endif return Screen_Send( text ) endfunction let g:screen_windowname = "python" command! -range -nargs=* FeedToScreen , call Screen_Exec()