Using vi with Lisp


Most Lisp developers prefer emacs to vi since emacs allows one to run Lisp within a separate buffer with a tightly integrated compile/test cycle. For those already familiar with vi, vi can do two of the most important functions you would need from the editor:

  • balance the parentheses.
    set sm turns on the blinking of matching parens as you type the close parenthesis.
    Typing % when the cursor is on a parenthesis will move the cursor to the matching parenthesis.
  • indent expressions.
    vi allows to set different modes, either by setting them in your .cshrc file in the EXINIT variable (as shown later) or by setting them once you are in vi using the command :set . The modes you are interested in are:
    • set ai turns on auto-indentation. This means that each line you type will match the previous line’s indentation.
    • set lisp turns on lisp mode. This means the indenting is done as required by Lisp.

    You can set the desired modes to vi by adding this line to your .cshrc file:

    setenv EXINIT 'map # Ji^M^[|set wm=6 para=lpppipnpbp sect=shuh showmatch ai'

    or by defining in your .cshrc file an alias command for vi (in the example shown here is li ) that includes all the modes you want when using lisp:

    alias li "vi '+set ic lisp ai wm=0 |map # Ji^M^[ |1' \!*"

    You can also set the modes after you are in vi by typing :set ai lisp

When using Xwindows, the easiest solution is to have two xterm windows, one for Lisp and one for vi. Do not forget to reload your file into Lisp every time you change it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s