« Post Index
Mar 19, 2012

Quickstart: Getting Started with Clojure via Vim, Lein, Slimv (Windows + Linux)

Hey! This post is a bit old. Here's one that describes fireplace.vim, which I recommend over Slimv now.

You'll need a command line for this. Here's the quick view:

  1. Install leiningen
  2. Install Slimv
  3. Install swank-clojure
  4. Create a project and get started

Install leiningen

Leiningen is a combination buildout/package management script for clojure. In Windows, you'll need lein.bat; on *nix, just lein will do.

Get that here

Get the one you need from the link, and make sure it's in your PATH. You have a user-space bin/ area where you keep your command-line executables, right? That's outside the scope of this article, but if you don't have one, get one.

I also had to get wget.exe and put it in the path; I got mine from http://users.ugent.be/~bpuype/wget/wget.exe.

Once you have lein, you can run the self-install to finish the job:

> lein self-install

Install Slimv

I assume you found this article looking for something like "vim clojure", so I assume you have pathogen. If not, get it. After that, it's as easy as downloading slimv and putting its contents in the bundle/ directory. We'll see if it worked later.

Install Clojure-swank

Leiningen makes this as easy as

> lein plugin install swank-clojure 1.4.0

I'm not actually sure this is necessary, but hey, it worked for me.

Usage

Lein really prefers that you do your development in a well-defined project directory. You can make one with:

> lein new test-app

This will create a new clojure project "test-app" in a new directory from where you ran the command. Then, cd into that directory and run:

> lein swank

Slimv claims to have the ability to run this for you, but it didn't work for me on windows. Besides, this way you're running it from your proper project. Now, you can open the src/test-app/core.clj file in vim (this might be called something else for you). It will have a namespace at the top already; I added the rest in so that you had something to test on:

1 2 3 4 5
(ns test-app.core)
 
(defn fact [x] (reduce * (range 1 (inc x))))
 
(fact 5)

Basic commands:

1) Turn off paredit using ",(". It will be annoying for you until you get used to it.

2) Open up the swank connection using ",c", outside of insert mode of course.

3) Go within the (defn...) and type ",d". This is a shortcut to evaluating the defn that your cursor is in.

4) Highlight the opening paren of the (fact 5) statement and type ",e". This will evaluate the current form.

That's about it! You should see the results in the swank window in vim as you do all that.

A special message

This is where the affiliate links live, but hear me out! I use these two services every day, and I wouldn't recommend them if I wasn't satisfied.

DigitalOcean - Purveyors of fine (and inexpensive) virtual servers. I use DigitalOcean to host Address Bin and a few others; it's my go-to host. Use this referral link for a $10 credit.

AirBnb - I've been living in AirBnbs for a few months now, and plan to for many more. If you've ever wanted to try them out, you can get a $25 discount from this referral link.