Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

20090506

Send text from vim to any REPL

Like I said back in April, I'd been looking for a convenient way to interact with any REPL from vim. Nothing had been satisfactory until I found Mr. Martinez's vicle.vim, which is in turn based on Jonathan Palardy's slime.vim. Thanks to both of them! I really learned a lot. Vicle was a great starting point. However, I wanted a little different behavior from it. It needed modification to play well with GHCi and literate Haskell.

Now I have a decent initial version. I've tried single lines with GHCi, Python, and the shell. I've done blocks in GHCi. All seem to work fine. I guess any REPL works for single lines: Octave, R, maybe an ftp session, etc. Multiple lines with a REPL other than GHCi will require modification of the script. Please try it and let me know if it has problems or if you have any suggestions on how it could be improved. it requires GNU Screen. The biggest problem I know of with it is the 4096 byte limitation mentioned by Mr. Martinez. It would be nice to find a way around that.

Like vicle.vim and slime.vim, you will need GNU Screen. I start it with something like this:
screen -S haskellSession -t haskellSession ghci
Map the commands at the bottom to convenient keys in your .vimrc. I use Enter for :SendtoreplSend and in visual mode also Enter for :SendtoreplSendBlock. For blocks, it's also convenient to do something like map F10 to the command sequence "vip".

Download sendtorepl.vim: http://www.srl.im.dendai.ac.jp/renick/sendtorepl.vim

It's time to get busy using this.

20090504

For editline, don't bind jj to vi-command-mode!

I've hesitated posting my version of vicle because I was having what I thought was a weird bug. Somehow, only things with "j" in them were not working. It seemed like "j" and the next character were always omitted from the input to ghci. Finally it occurred to me to try sending the output to bash rather than ghci, and suddenly there was no problem. So the problem was in ghci. Then I remembered that I had done some things in .ghci and .editrc. The latter is where I found I had a line "bind jj vim-command-mode". That turned out to be really bad choice.

And here's where I got that from:
bind -v
bind \\t rl_complete
bind ^L ed-clear-screen
bind jj vi-command-mode <<<--- DON'T DO THIS!!! Esc is good enough! Remap the Windows key or CapsLock to Esc if necessary.

http://www.nabble.com/example-editrc-td21152004.html

I'm grateful to Brian for that message, because it showed me how to get vi bindings in ghci. However, that jj line cost me at least a couple of hours! That's a lesson to myself not to blindly copy and paste without understanding what I'm copying and pasting.

*slaps self upside the head*


Now I can finish cleaning up my version of vicle and post it.