For the past few months, I've been involved in an SICP study group that uses Scheme as the programming language of choice. As most programmers know, Emacs is the de facto standard tool for Lispers. But, Vim + *nix shell is my preferred toolset: at least until I am convinced that another, more specialized tool is warranted. I don't dislike Emacs (that much). Since the SICP material is challenging enough, I decided not to complicate things by fiddling with Emacs.
So, instead, I was able to fiddle with Vim and cobble together a reasonable Lisp programming environment using Vim, screen, and the Scheme interpreter of choice for the SICP book, MIT/GNU Scheme.
To get this to work, I assume you are working on some *nix operating system, such as Mac OS X or Linux.
- Install MIT/GNU Scheme
- Install GNU screen
- Install the Screen (vim + gnu screen) Vim plug-in
- Add the following configuration lines to your .vimrc file (located in your home directory):
"For screen.vim send block
These two lines map the CONTROL+c CONTROL+c (double Control-c) key sequence to the Vim command "vip" and then send the result of "vip" to the ScreenSend function (provided by the Screen plug-in). The net effect is that double Control-c will highlight whatever block of code your cursor is in and send that block to whatever process ScreenSend is mapped to. In our case, that will be the Scheme interpreter.
"to SendScreen function
"(eg Scheme interpreter)
vmap <C-c><C-c> :ScreenSend<CR>
nmap <C-c><C-c> vip<C-c><C-c>
- Now, we are ready to open a console window, fire up Vim, and write some Scheme code. After opening Vim, execute the ScreenShell command:
:ScreenShell scheme
This command will launch a screen instance, attach the currently running Vim process to the upper screen window, and then launch a new Scheme process and attach it to the lower screen window. This gives you a nice two window setup with your editor above and your interpreter below. Now you should see something like the following:
- Let's go ahead and type some Scheme code in the top window, the Vim buffer:
(+ 1 1)
With your cursor somewhere on or between the opening and closing parentheses, type the double Control-c key sequence. You should see the code highlighted and then interpreted in the bottom window:
Tada! You now have a simple Lisp REPL programming environment.
There are lots of enhancements you'll want to make to this basic set-up if you plan to do any significant Lisp coding. For instance, you'll want to add plug-ins for syntax highlighting and parenthesis matching. But, this is a good start for exploring Lisp in your favorite editor.
Let me know other ways you've set up Vim to work with Lisp.





Recent Comments