VSCode and Calva quick start
Run the command code .
from the root of a Clojure project.
Alternatively, run VS Code and use Ctrl+k Ctrl+o
or the File > Open Folder menu to open the Folder that contains your Clojure project. Select the top level of the folder, e.g. playground
and click OK
MacOSX Keys - Option or Alt
Start a REPL for basic projects
ctrl+alt+c ctrl+alt+j
to start a REPL click on the nrepl name in the bottom left of VSCode UI.
Select either Clojure CLI
or Leiningen
when prompted for the project type
Wait a few moments for the REPL to start.
A new CLJ REPL tab 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. Ask your coach for help if you see output other than that below.
Try running a REPL in the command line and connecting to it (details at bottom of this page).
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
To use Leiningen, type the command lein repl
in the terminal.
To use Clojure CLI tools, us the practicalli/clojure-deps-edn aliases and run a REPL that also starts an nREPL server
clojure -M:middleware/cider-clj
If you also wish to have an interactive terminal REPL, include rebel readline when starting the REPL
clojure -M:repl/rebel-nrepl
Connecting to an external REPL from Calva
Ctrl+Alt+c Ctrl+Alt+c
will open a command pop-up asking you to enter host and port. These details were shown when the REPL was run in the terminal.
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
Developing your project
Once you have a running REPL, use these commands to help you develop your code.
MacOSX Keys - Option or Alt
You can run tests from Calva too...
REPL history
Commenting / uncommenting code
Use ;;
at the start of a line, which comments it out.
Line comments keybindings ?
Increase / decrease font size
Ctrl +
and Ctrl -
will increase and decrease the size of the whole editor.
Ctrl Shift P
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"
Structured editing - Paredit
Once you get the basics of Clojure development, you can try structural editing which is a way to edit your code 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.