Monday, March 7, 2011

Emacs' slimey goodness... in Vim!

Using screen, the Slime plugin lets you effectively add the REPL of your favorite dynamic language to Vim.

To install it:
  1. Download the plugin. Extract it to your .vim folder.
  2. If you haven't already, install GNU screen.
To use it:
  1. Start a terminal, and type $ screen -S replshell . The term 'replshell' can be replaced by any term you prefer.
  2. Invoke the interpreter of the language you'd like to use. For eg., $ python
  3. Start a new terminal, and open vim.
  4. Type some python code.
  5. When you're done, move your cursor to the starting line of a 'paragraph' which is effectively an unbroken list of lines. This could be a class definition, or just a function.
  6. Hit Esc, then C-c, C-c.
  7. You'll be asked to enter in the name of the screen you would like to send the text to. Type in replshell. This happens just this once for this session.
  8. You'll be asked to name the window, the default option being window0. Hit Enter.
  9. The code should appear on the other terminal. Hit Enter to see it execute.
  10. Celebrate!
This can be used for Ruby or even Common Lisp. Have fun!