VS Code with VSpaceCode and Calva
The Calva User Guide provides a detailed guide to the features of Calva, although the key bindings for VSpaceCode are not included in that guide.
Open the VSCode editor and open the root folder of your project. Then add use let Calva start your project REPL and connect.
Open Project Folder in VSCode
SPC SPC
to open the command menu and type file open folder
and select the folder that contains the Clojure project.
Select the top level of the folder, e.g. playground
and type Ctrl-l
Start a REPL for the project
, "
to jack-in to a Clojure REPL for the project. This starts an external REPL process and connects to it.
Alternative, use
, '
to connect to an external REPL process that has already started.
Select either deps.edn
for Clojure CLI or Leiningen
when prompted for the project type
Wait a few moments for the REPL to start.
A new REPL window will open when the Clojure REPL is ready
Troubleshooting
If the REPL did not start, the nREPL link in the bottom blue bar will show the word "Disconnected".
Open the Output tab to see the progress of the REPL starting.
Try running a REPL in the command line and connecting to it (details at bottom of this page).
Evaluating Clojure code
, e f
to evaluate a top-level expression and see the results inline. Or , e s
to select a specific expression and , e e
to evaluate it.
, e l
to clear all the evaluated results.
Running tests
, e n
to evaluate all the unit test code in the current window
, t a
to run all the unit tests in the project
, t f
to run just the failing tests
Keybinding | Description |
---|---|
, t a |
Run all tests in the project |
, t f |
Run all tests for the current namespace |
, t n |
Run all tests for the current namespace |
, t t |
Run all tests for the current namespace |
Commenting / uncommenting code
SPC c l
toggles a comment on the current line.
Use the Add Line Comment command to place ;;
at the start of a line, which comments it out.
Linting
, c n
and , c N
cycle through clj-kondo linting warnings
Increase / decrease font size
Ctrl +
and Ctrl -
will increase and decrease the size of the whole editor.
SPC SPC
and type the command Preference: Open Settings (JSON)
to open the settings.json
configuration file. Update the value for editor.fontSize
and save the file. The font should update immediately in the VS Code UI.
Other useful options that can be added to the settings.json
configuration
"workbench.colorTheme": "Solarized Light",
"editor.fontSize": 14,
"editor.fontFamily": "'Fira Code', 'Ubuntu Mono', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
"window.zoomLevel": 1,
"calva.paredit.defaultKeyMap": "strict"
Structural editing - Paredit
, k
is the structural editing menu.
Structural editing ensures code can be written and edited without breaking the structure of Clojure. Structural editing ensures you dont have uneven parentheses, ()
, []
, {}
, etc.
The Calva visual Guide to Paredit includes lots of examples of using Structural editing.
Start a REPL on the command line
Ctrl+` toggles open the VSCode Integrated terminal. Or open your operating system terminal.
Windows GitBash users
In the terminal, change to the folder than contains your project, e.g. cd projects/clojure/playground
For a Clojure CLI project, use the command clojure -M:env/test:middleware/cider-clj
to run a REPL process for Calva to connect to via nREPL, using the practicalli/clojure-deps-edn configuration.
For a Leiningen project, use the command lein repl
Connecting to an external REPL from Calva
, '
to connect to an external REPL process.
Select either Clojure CLI
or Leiningen
when prompted for the project type
Confirm the host and port of the REPL, this should be automatically detected. These details were shown when the REPL was run in the terminal.
Wait a few moments for the REPL to start.
A new REPL window will open when the Clojure REPL is ready
In the bottom left of the VS Code window, check the status of the nrepl connection. If you are connected, then the disconnected status should disappear