This is the first in what I’ve decided will be a series of infrequent posts dealing with my experiments with Vim.
There’s already a ton of material on this out there, but I’ve decided against my better judgement to add to the million articles and blog posts out there.
This will give me a place to point people to when they ask me how to do X in vim, and, it will simultaneously serve as an archive for my experiments with vim. You know, incase I need to go back and redo my
.vimrc (This happens more frequently than I’d care to admit)
I have these phases of intense workflow, tool and knowledge gathering followed by long periods where I use some of these newer tools, tips and tricks and the rest are forgotten with time.
I had one of these phases of intense learning these past couple of days.
I had a huge bout with irssi, vim, and a smaller one with pentadactyl and OSX.
I’ll be writing about the Vim side of things in this post. Mostly because I didn’t find this particular combination of things anywhere exactly.
These past couple of days I’ve been mucking around with a couple of functional languages, namely Haskell and Racket.
Now the thing about functional languages (especially the more lisp-y versions) is that they work great with REPLs.
Now I’m no stranger to REPLs, I’m a python programmer before anything else and I’ve had the pleasure of using both the standard python REPL and iPython (a fancier python REPL with loads of extra features).
The thing that almost always annoyed me so far as a Vim user has been the lack of an integrated editor/REPL that allows me run code right from my editor.
Everything I’d tried so far was/had been a hack.
I gradually learnt to use Tmux. Tmux’s split panes helped.
I switched from:
edit text --> save text, close vim --> run code from cli --> check errors --> open vim --> repeat
edit text --> save --> switch pane --> run code from cli --> switch pane --> check errors --> edit text --> repeat
which was/is somewhat faster… but there was something missing.
I’d seen Emacs users who used Lisp write code and run it right from the editor with code magically running from inside their edit buffer/pane.
So that it actually becomes:
edit text --> save --> run from editor --> check errors --> edit text --> repeat
No switch panes, buffers, jumping in and out of your editor.
For the lazy programmer this is better because it’s fewer steps.
For the efficiency seeker it’s much much faster and speeds up development significantly.
Now I wanted this for vim, and for a long time I didn’t search hard enough because I got by with the afore-mentioned tmux split method. But no more!
While setting up vim for use with racket I ran across this fine page Vim for Racket
This has some amazing stuff, but the gold-mine here is slime.vim , it gives you the same capabilities advantages as the live REPL evaluation in Emacs, in vim!
It uses a mixture of
screen if that’s your thing),
vim and some behind the scenes file sockets and other magic to dump whatever you want from the editor into the REPL and which then evaluates the code.
The nice thing about it?
It’s not racket specific, you can use it with any language that has a REPL/interpreter.
There’s an even fancier variant with many more features of this called slimv which I haven’t gotten around to trying but looks very promising.
Now to other absolutely fabulous but frivolous discovery.
Vim 7.3+ has a feature called conceal.
This lets you select strings and replace them with a single character. How might this help you ask?
Well, a programming languages are ,in some sense, an abstraction of, or atleast draw heavily from mathematics.
Now mathematics works with lots of Greek Symbols, and some of that has carried over to programming languages. But since it’s hard to actually type λ or Σ directly, we’re left with typing lambda or sum as words instead, which is fine, except it’s not as easy to read as a mathematical equation.
It converts lets you convert all your word-y keywords into beautiful looking greek symbols.
Why would someone want to do that?
It looks good!
I did say this was a frivolous one didn’t I?
If you’re a pythonista, there’s vim-cute-python
If anyone’s interested in what goes into the
.vimrc it’s not much, all I added was
au VimEnter * syntax keyword racketSyntax lambda conceal cchar=λ au VimEnter * hi! link Conceal racketSyntax au VimEnter * set conceallevel=2
Further reading and related links: