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 defs 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+wToggle pretty printing (
onby default):ctrl+alt+c pRun all tests:
ctrl+alt+c alt+tRun tests for current namespace:
ctrl+alt+c tRun current test:
ctrl+alt+c ctrl+alt+tForward Sexp:
ctrl+alt+rightBackward Sexp:
ctrl+alt+leftForward Down Sexp:
ctrl+downForward up Sexp:
ctrl+alt+downBackward Down Sexp:
ctrl+alt+upBackward Up Sexp:
ctrl+upDelet Sexp forward:
ctrl+shift+deleteDelete Sexp backward:
ctrl+alt+backspaceDelete forward to end of list:
ctrl+deleteDelete backward to start of list:
ctrl+backspaceShow preivous REPL history entry:
alt+upShow next REPL history entry:
alt+down