Skip to content

Customizing Calva

Don't like the defaults? On this page we can collect some of the customizations that people have done, and maybe write a thing or two about it some day.

Tip for VS Code newcomers: The search box in Settings is your friend. Also, some Calva settings are more complex than the Settings UI can handle. VS Code will then show you a link to settings.json. And VS Code's built-in json extension is awesome. To add settings for Calva's Pretty Printing, for example, search for ”prettyprint” in VS Code Settings and follow the link to settings.json. Start typing ”calvapretty” until auto-complete suggests calva.prettyPrintingOptions. Press ENTER and VS Code will fill in these defaults:

    "calva.prettyPrintingOptions": {
        "enabled": true,
        "printEngine": "pprint",
        "width": 40
    },

Clojure Defaults

Calva sets some VS Code settings for all Clojure files. Some of these are needed for Calva to function correctly, which should not be tampered with unless you really know what you are doing, and some of them are convenient defaults. If you add a setting to your settings.json and accept the snippet help you get when you type "[clojure]", you will get the Calva defaults pasted:

    "[clojure]": {
        "editor.wordSeparators": "\t ()\"':,;~@#$%^&{}[]`",
        "editor.autoClosingBrackets": "always",
        "editor.autoClosingQuotes": "always",
        "editor.formatOnType": true,
        "editor.autoIndent": "full",
        "editor.formatOnPaste": true,
        "files.trimTrailingWhitespace": false,
        "editor.matchBrackets": "never",
        "editor.renderIndentGuides": false,
        "editor.parameterHints.enabled": false
    }

Pretty Printing

Calva's pretty printing mode can be configured a bit. See Pretty Printing.

Calva Highlight

Calva takes care of syntax highlighting, and also provides some features not available through VS Code's highlighting mechanism. These extras include rainbow parens, sane bracket matching, and comment form dimming/highlighting.

You are in charge of how brackets and comments are highlighted via the calva.highlight.<setting> settings:

Setting Meaning Example
enableBracketColors Enable rainbow colors true
rainbowIndentGuides Enable rainbow indent guides true
highlightActiveIndent Highlight the active indent guide true
bracketColors Which colors to use ["#000", "#999"]
cycleBracketColors Whether same colors should be
reused for deeply nested brackets
true
misplacedBracketStyle Style of misplaced bracket { "border": "2px solid #c33" }
matchedBracketStyle Style of bracket pair highlight {"backgroundColor": "#E0E0E0"}
ignoredFormStyle Style of #_... form {"textDecoration": "none; opacity: 0.5"}
commentFormStyle Style of (comment ...) form {"fontStyle": "italic"}

Note

The VS Code built-in settings editor.renderIndentGuides and editor.highlightActiveIndent do not have any effect, since the former is switched off by the Clojure Defaults, mentioned above. Use Calva Highlight's rainbowIndentGuides and highlightActiveIndent instead. They are different from the built in ones in that they are independent, meaning you can choose to have active indent highlighted while the guides generally are not rendered (this is the default, even).

Automatic Parmaeter Hints Poppup

Calva has helpful parameter hints to aid when typing function calls. They look like so:

image

To have the hints automatically pop up when you are typing, set editor.parameterHints.enabled to true in the above [clojure] scoped setting. (To call them up on demand the default VS Code keybindings are cmd+shift+space on Mac and ctrl+shift+space on Linux/Windows.)

Code Formatting

See Formatting for information on how to configure this.

Jack-in and Connect Sequences

Jack-in and Connect are very customizable through Custom Connect Sequences.

Key bindings

Here are a collection of custom keybindings from here and there.

Are you a vim extension user? See: Using with VIM extension.

Paredit

Please be aware that the REPL window does not handle chorded shortcuts. Something to keep in mind when customizing Paredit shortcuts, because those are dispatched onto the REPL window. So, best to avoid chorded shortcuts for Paredit.

Wrap using (, [, { (like Cursive)

Something I use in IntelliJ/Cursive is the ability to select an expression and hit one of (, [, { to wrap it. And after wrapping the expression I don't want the selection anymore, so if I were wrapping (foo) then I would want to get ( | (foo)) where | would be my cursor.

Here's how you can make this work with Calva Paredit: Update all of the Paredit: Wrap Around ... commands so that their respective shortcuts are the wrappers themselves and update the when clause to include editorHasSelection (otherwise when you open a paren the next expression would get slurped in).

The change would look like this in your keybindings.json:

    {
        "key": "shift+9",
        "command": "paredit.wrapAroundParens",
        "when": "editorTextFocus && editorHasSelection && !editorReadOnly && editorLangId =~ /clojure|scheme|lisp/ && paredit:keyMap =~ /original|strict/"
    },
    {
        "key": "[",
        "command": "paredit.wrapAroundSquare",
        "when": "editorHasSelection && editorTextFocus && !editorReadOnly && editorLangId =~ /clojure|scheme|lisp/ && paredit:keyMap =~ /original|strict/"
    },
    {
        "key": "shift+[",
        "command": "paredit.wrapAroundCurly",
        "when": "editorHasSelection && editorTextFocus && !editorReadOnly && editorLangId =~ /clojure|scheme|lisp/ && paredit:keyMap =~ /original|strict/"
    }