by goldfeld · 12y ago · 0 comments
There might as well be no concept of "words" or "lines" in a seasoned lisp programmer's mind, there's only sexps and forms. And it's so much easier to reason that way, which is not a fault of vi's grammar but arguably a fault of most programming languages' grammars. It's that fabled saying that you should rather have one data structure (sexps) with 100 operations on it than 10 structures (words, lines, bracketed expressions, paras) with 10 operations each. Vi at least makes those operations consistent across structures and thus trivially deducible.
I tend to use vi-bindings in my Emacs coding (Clojure), but I'm more and more relying on Paredit. However I'm immensely happy to have vi commands for editing prose on Emacs, and I don't think there's anything more powerful than vi for that.
Forgive me for plugging my own project, but vim-sexp¹ provides exactly this abstraction as Vim text-objects, which in turn may be composed with _any_ of the operations in Vim.
S-expressions as text-objects is an amazing marriage of ideas. For example, the sexp text object can be used equally as an argument to eval, yank, delete, change, select, move, and every other operator, builtin or user-defined, each optionally accepting a count. After that, the whole operation can be repeated on a new S-expression with a simple tap of the repeat command. Because Lisp forms are so regular, these actions are precise and highly reliable.
The origin of this saying is Epigrams in Programming, by Alan Perlis.
This really can't be overstated.
Even if you don't really use Paredit or any kind of special tool S-expressions lend themselves to easy modification. Since a Lisp program is, by virtue of the structure, organized by default into easily separated components there is no need to think about anything else other than just expressions.
When I write Racket code (in Emacs), I organize and move code in expressions instead, and if I wanted to move a certain expression I would just move to the enclosing paren and hold shift while saying "move to matching paren" and the whole expression will be marked and I can do whatever I want with it.
I used to use vim before and while I did "get it" after a while I switched to Emacs when I started learning Lisp because I figured I could immerse myself in Lisp code with Emacs.
The thing about it is that since I've coded almost exclusively in Lisps since then I haven't really needed what vim does best. At some point a while ago there were a slew of posts about vim and I looked at maybe getting evil-mode for emacs, but I don't know if I see the point when I almost exclusively deal with sexps.