This is a study note on how to develop Clojure using VS code. It is based on the Calva Usesr Guide.
1 Installation
There are two competing VS code extensions: Calva and Andrey Lisin’s clojureVSCode. Calva is the better one in terms of recency, commits and collaborators.
Calva is a REPL powered Clojure and Clojure Script development tool that supports inline code evaluation, Paredit, code formatting, a test runner, syntax highlighting, linting, and more.
2 Jack-in
To provide many of its IDE features, Calva relies on nREPL middleware, mainly cider-nrepl
and, for ClojureScript, piggieback
. Jack in
creates the command that starts Calva with these dependencies satisfied. The details are explained in Learn about Jack-in.
Jack-in supports Leiningen and Clojure CLI for Clojure. It supports Figwheel Main, shadow-cljs and Nashorn for ClojureScript.
Open a project root folder in VS Code, then ctrl+alt+c ctrl+alt+j
to open start Jack in, then specify project type and profile to start.
Calva only supports one project at a time per VS Code window. For a full stack project, create two workspaces and use them in two windows.
See Custom Connect Sequences for customizing Jack-in.
3 Code Evaluation
Calva has the notions of the current form
and the current top level form
. When you place the cursor to any code, it highlights the current form
. The current top level form
refers the various def
s such as defn
, defthis
and defthat
. The (comment ...)
creates a new context for top level forms.
- Load current file:
ctrl+alt+c enter
- Evaluate current form:
ctrl+enter
- Evaluate current top-level form:
alt+enter
- Clear inline evaluation result:
esc
- Copy last evaluation results:
ctrl+alt+c ctrl+c
4 Other commands
You can find all commands in Feature Contributions
in the Calva extension page. Commonly used commands:
- Expand selection:
ctrl+w
Shrink selection:
ctrl+alt+w
Toggle pretty printing (
on
by default):ctrl+alt+c p
Run all tests:
ctrl+alt+c alt+t
Run tests for current namespace:
ctrl+alt+c t
Run current test:
ctrl+alt+c ctrl+alt+t
Forward Sexp:
ctrl+alt+right
Backward Sexp:
ctrl+alt+left
Forward Down Sexp:
ctrl+down
Forward up Sexp:
ctrl+alt+down
Backward Down Sexp:
ctrl+alt+up
Backward Up Sexp:
ctrl+up
Delet Sexp forward:
ctrl+shift+delete
Delete Sexp backward:
ctrl+alt+backspace
Delete forward to end of list:
ctrl+delete
Delete backward to start of list:
ctrl+backspace
Show preivous REPL history entry:
alt+up
Show next REPL history entry:
alt+down