Sending input to a screen window from vim

妖精的绣舞 提交于 2019-12-23 04:14:17

问题


I have a vim function set up where I can highlight a line of text and execute in clojure. Here's the function:

 function! Clojure_execline()
     let cl = (getline(line(".")))
     // ...
     exec 'clojure -e "' . cl . '"'
 endfunction

The problem with this is that it's slow to start and because it spawns a new clojure session every time I run it, I can't call a function I ran previously. Ideally, I'd like for a hidden repl to be running where I could send input from vim and retrieve the output from as well. I learned about gnu screen and thought it could help me, but I don't know how to send input from one screen window to another.

To clarify my problem, take this line of clojure:

(defn add2 [x y] (+ x y))

I'd like to be able to highlight this line in vim and execute in a running repl. I want to be able to call the line below and have it execute in the same repl:

(add2 4 5)

Afterwards, I'd like to be able to get the output of the function.

So, basically, my question is, how do I send input from one screen window to another?


回答1:


Jake McCrary's suggestion is a good one. There are also a couple other scripts available, probably based on same idea:

VimClojure, which says it does "repl in a vim buffer"

and

slimv, specifically supports Clojure

and

Gorilla, I think VimClojure, above, is based on Gorilla

I don't know whether VimClojure actually does what you want, sending result back from Screen to buffer in Vim. One way to do that, I think, would be to finagle something using Vim's client-server functionality, possible with the --remote-send flag. See:

:h client-server
:h --remote-send



回答2:


I don't have an exact answer, but it might be worth taking a look at slime.vim and seeing if anything can be learned from it.

blog post about it

script at vim.org




回答3:


Found what I was looking for. You can execute this from a terminal to send a string directly to the stdin of a screen window:

$ screen -X stuff "ls -l\015" # \015 sends a carrige return.



回答4:


You might also be interested in Conque http://code.google.com/p/conque/

I use it for Scala



来源:https://stackoverflow.com/questions/4318372/sending-input-to-a-screen-window-from-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!