Lisp in Vim - Susam Pal
Lisp in Vim
By Susam Pal on 07 Dec 2019
Introduction
Fifteen years ago, writing Lisp code in Vim was an odd adventure.<br>There were no good plugins for Vim that assisted in structured<br>editing of Lisp s-expressions or allowed interactive programming by<br>embedding a Lisp Read-Eval-Print-Loop (REPL) or a debugger within<br>the editor. The situation has improved a lot since then. In the<br>last ten years, we have seen active development of two Vim plugins<br>named Slimv and<br>Vlime. Slimv is over<br>10 years old now. Vlime is more recent and less than 3 years old<br>right now. Both support interactive programming in Lisp.
I am going to discuss and compare both Slimv and Vlime in this<br>article. I will show how to get started with both plugins and<br>introduce some of their basic features. I will not cover everything<br>though. This is not a tutorial. For tutorials, see<br>the References section.
If you are looking only for a comparison of the two plugins or a<br>quick recommendation, jump directly to the<br>Comparison of Slimv and Vlime<br>section or the<br>Quick Recommendation<br>section.
Contents
Introduction
Background
Lisp
Emacs: SLIME
Vim: Slimv/Vlime
Vim Plugin Management
Software Versions
Get Started
Get Started with Slimv and SBCL
Get Started with Vlime and SBCL
Get Started with Paredit
Use Debugger and Inspector
Use Debugger and Inspector with Slimv
Use Debugger and Inspector with Vlime
Trace Function
Trace Function in Slimv
Trace Function in Vlime
Nifty Features
Evaluate Top-Level Form
Rainbow Parentheses
Argument List
Omni-Completion
Describe Symbol
Expand Macro
Cross Reference
Other Common Lisp Implementations
Use Slimv with CLISP
Use Slimv with ECL
Use Vlime with CLISP
Use Vlime with ECL
Other Lisp Dialects
Use Slimv with MIT/GNU Scheme
Use Slimv with Clojure
Comparison of Slimv and Vlime
Quick Recommendation
Disclosure
References
Background
Before we get started with Slimv and Vlime, it would be nice to take<br>a brief look at the heritage behind these plugins. These plugins<br>provide Lisp development environments for Vim, so their story begins<br>with Lisp.
Lisp
Lisp is a family of programming languages with a distinctive, fully<br>parenthesised prefix notation. It is quite unlike most of the other<br>popular programming languages today like C, Python, Ruby, etc. Its<br>homoiconic nature and its powerful macro system that can transform<br>arbitrary Lisp expressions make it such a flexible, versatile,<br>extensible and introspective language that articles describing Lisp<br>often have the word "enlightenment" in them. For example, see the<br>following articles:
Beating the<br>Averages (by Paul Graham)
The<br>Nature of Lisp (by Slava Akhmechet)
How<br>Lisp Became God's Own Programming Language (by Sinclair<br>Target)
Lisp has been described in various ways by various eminent<br>personalities in the history of computing. Alan Kay has famously<br>described Lisp as:
The greatest single programming language ever designed.
John Foderaro has written this about Lisp:
Lisp is a programmable programming language.
Eric S. Raymond has expressed the enlightenment one experiences by<br>learning Lisp in his famous article titled<br>How To Become A Hacker:
Lisp is worth learning for the profound enlightenment experience you<br>will have when you finally get it. That experience will make you a<br>better programmer for the rest of your days, even if you never<br>actually use Lisp itself a lot.
Randall Munroe, the creator of the<br>XKCD webcomic has dedicated two<br>comic strips to Lisp:
Lisp by Randall Munroe<br>(Source: https://xkcd.com/224/)
Lisp Cycles by Randall Munroe<br>(Source: https://xkcd.com/297/)
Developed in 1958 by John McCarthy, Lisp is the second oldest<br>programming language in use today. Only Fortran is older, by one<br>year. Some of the popular Lisp dialects today include Common Lisp,<br>Scheme and Clojure. Most of this article would focus on Common<br>Lisp. Scheme and Clojure would be discussed briefly towards the end<br>of this article.
Emacs: SLIME
Many Lisp programmers immediately think of Emacs when they think of<br>writing Lisp code. Emacs is a family of text editors. An Emacs<br>editor itself is typically implemented in a dialect of Lisp. There<br>is an Emacs mode named SLIME that provides excellent support for<br>programming in Lisp. SLIME stands for Superior Lisp Interaction<br>Mode for Emacs. First released in August 2003, SLIME was created by<br>Eric Marsden and then later developed further by Luke Gorrie and<br>Helmut Eller. It offers a Read-Eval-Print-Loop (REPL), integrated<br>debugging and interactive evaluation of expressions, all available<br>right within the editor. There are several nifty key bindings<br>available to compile and evaluate parts or whole of the code in the<br>current buffer.
SLIME works by launching a Swank TCP server. Swank is a backend<br>server program written in Common Lisp that listens on a socket to<br>receive SLIME commands from Emacs and execute them. SLIME is so<br>useful that it is considered to be indispensible by many Lisp<br>programmers...