Using cider-mode
cider-mode is a pretty standard Emacs minor mode, which exists mostly to provide a
common keymap for all of CIDER’s REPL-powered commands that are meant to be used
from Clojure(Script) source buffers.
There you’ll find commands for evaluation, code and documentation lookup, debugging and other related functionality. This mode is the very heart of CIDER and it’s important to master it, so you can be productive.
Enabling cider-mode
cider-mode is normally enabled automatically when you start CIDER, but you can also enable it explicitly for Clojure(Script) buffers like this:
(add-hook 'clojure-mode-hook #'cider-mode)
or if you are using clojure-ts-mode:
(add-hook 'clojure-ts-mode-hook #'cider-mode)
There’s no need to enable it explicitly for modes derived from clojure-mode or clojure-ts-mode like clojurescript-mode and clojure-ts-clojurescript-mode.
|
Disabling cider-mode
cider-mode is normally disabled automatically when you quit CIDER, but you can also disable it in any buffer explicitly by typing M-x cider-mode (provided it’s already enabled in that buffer).
Basic Workflow
Typically you’d begin your interaction with any source buffer by evaluating it with C-c C-k. Afterwards you’d normally evaluate just individual forms with C-c C-e (evaluate preceding form) or C-c C-c (evaluate current top-level form).
cider-mode shows at a glance whether the buffer is in sync with the REPL - a ` not-loaded` or ` stale` marker in the mode line, plus green/amber markers in the fringe. See Evaluation and Load-State Indicators.
|
From time to time some evaluation would take forever and you’d interrupt it with C-c C-b.
Jumping between source files and the REPL is as easy as pressing C-c C-z. If you invoke the command with a C-u prefix, while in a source buffer, it will also change the namespace of the REPL buffer to match that of the source buffer.
It’s also highly likely that you’d look up some definition with M-. or some documentation with C-c C-d C-d.
| Definition and documentation lookup commands work with both Java and Clojure. |
If you’re struggling to remember the name of some var you need, cider-apropos (C-c C-d a or C-c C-d C-a)
and cider-apropos-documentation (C-c C-d f or C-c C-d C-f) will help you find vars matching some string.
cider-mode also provides you with code completion that works out-of-the-box and requires no extra setup and eldoc integration.
Those few essential commands can get you really far in your day to day work. Keep on reading for a lot more information!
A Note on Keybinding Conventions
Many of CIDER’s keybindings are modeled on SLIME (the venerable Common Lisp environment) and on Emacs’s own bindings for evaluating Emacs Lisp. The essentials line up almost everywhere - C-x C-e (eval last sexp), C-M-x (eval top-level form), C-c C-k (load), C-c C-m / C-c M-m (macroexpand), M-. / M-, (jump to a definition and back), C-c C-d C-d (docs), C-c C-z (switch to the REPL) and C-c C-b (interrupt). We try to diverge only rarely, so that switching between Clojure, Common Lisp (SLIME/Sly) and Scheme (Geiser) stays as frictionless as possible.
Where CIDER does differ, it’s usually for a reason:
-
Inspect is on C-c M-i rather than SLIME’s C-c I. Emacs reserves
C-cfollowed by a plain letter for users' own bindings, so we keep to the modifier-and-control space that’s meant for modes. -
Tracing is on the C-c M-t prefix rather than SLIME’s C-c C-t, because CIDER uses C-c C-t for its test commands (something the Lisps don’t have).
-
CIDER has far more evaluation commands than the other tools, so beyond the handful of familiar top-level bindings the rest live under a dedicated C-c C-v eval prefix, rather than each claiming its own global key.
Command Menus
Each of CIDER’s command prefixes opens a transient menu that lists the commands in that group, grouped and labelled, so you can discover them without memorizing every key. For example, C-c C-d opens the documentation menu, C-c C-v the (large) evaluation menu, C-c C-t the test menu, and so on.
This is not a modal change: the menus reuse the same sub-keys as before, so
typing a full sequence still fires instantly without the menu ever popping up.
C-c C-d C-d runs cider-doc immediately; the menu only appears if you
pause after the prefix. There’s also a top-level cider-menu command (not
bound by default) that dispatches into all of the group menus, magit-style.
Some menus also offer arguments (toggled with - keys, magit-style) that tweak the commands for a single invocation, without touching your saved configuration:
-
the test menu (C-c C-t) can filter by selectors;
-
the namespace menu (C-c M-n) makes `cider-ns-refresh’s modes explicit toggles;
-
the macroexpand menu (C-c M-m) controls the expansion’s rendering;
-
the pretty-print menu (C-c C-v f) lets you pick the printer;
-
the jack-in/connect menu (C-c C-x) can set CLI aliases, the ClojureScript REPL type, or edit the command before it runs.
Opting out of the transient menus
If you’d rather keep the old behavior - a bare prefix keymap, e.g. for use with which-key or because you’ve added your own bindings under one of these prefixes - the original keymaps are still defined. Just rebind the prefix key back to its keymap:
(with-eval-after-load 'cider-mode
(keymap-set cider-mode-map "C-c C-d" 'cider-doc-map) ; documentation
(keymap-set cider-mode-map "C-c C-v" 'cider-eval-commands-map) ; evaluation
(keymap-set cider-mode-map "C-c C-t" 'cider-test-commands-map) ; test
(keymap-set cider-mode-map "C-c M-n" 'cider-ns-map) ; namespace
(keymap-set cider-mode-map "C-c C-j" 'cider-insert-commands-map) ; insert in REPL
(keymap-set cider-mode-map "C-c M-m" 'cider-macroexpand-map) ; macroexpansion
(keymap-set cider-mode-map "C-c C-=" 'cider-profile-map) ; profiling
(keymap-set cider-mode-map "C-c C-w" 'cider-who-map)) ; call-graph queries
A couple of groups don’t map one-to-one onto an old keymap:
-
The jack-in/connect prefix C-c C-x is bound on
clojure-mode-map(and the REPL), notcider-mode-map; rebind it tocider-start-mapthere to restore the old prefix. -
Tracing (C-c M-t) never had a dedicated keymap - it was just C-c M-t v and C-c M-t n. Its menu is purely additive (it also exposes
cider-list-traced,cider-untrace-alland the trace buffer), so there’s nothing to revert; rebind those two keys directly if you want the flat bindings back.
Key Reference
Here’s a list of the key bindings of cider-mode:
| Command | Keyboard shortcut | Description |
|---|---|---|
|
C-x C-e |
Evaluate the form preceding point and display the result in the echo area and/or in a buffer overlay (according to |
|
C-c C-v w |
Evaluate the form preceding point and replace it with its result. |
|
C-c M-e |
Evaluate the form preceding point and output its result to the REPL buffer. If invoked with a prefix argument, takes you to the REPL buffer after being invoked. |
|
C-c M-p |
Load the form preceding point in the REPL buffer. |
|
C-u C-c M-p |
Load the form preceding point in the REPL buffer and eval. |
|
C-c C-j c |
Copy the top-level form at point into the namespace’s rich |
|
C-c C-j v |
Move point into the namespace’s rich |
|
C-c C-v C-f e |
Evaluate the form preceding point and pretty-print the result in a popup buffer. If invoked with a prefix argument, insert the result into the current buffer as a comment. |
|
C-c C-v C-f d |
Evaluate the top level form under point and pretty-print the result in a popup buffer. If invoked with a prefix argument, insert the result into the current buffer as a comment. |
|
C-M-x |
Evaluate the top level form under point and display the result in the echo area. |
|
C-c C-v s |
If no region is active, eval the toplevel form with cider-eval-defun-at-point. If a region is active, run cider-eval-region |
|
C-c C-v l |
Evaluate the list around point. |
|
C-c C-v v |
Evaluate the form around point. |
|
C-u C-M-x |
Debug the top level form under point and walk through its evaluation |
|
C-c C-v z |
Evaluate the preceding top-level form up to the point. |
|
C-c C-v r |
Evaluate the region and display the result in the echo area. |
|
C-c C-b |
Interrupt any pending evaluations. |
|
C-c C-m (also C-c M-m 1) |
Invoke |
|
C-c M-m a |
Invoke |
|
C-c M-m e |
Expand the macro at point one step, inline in the source buffer. |
|
C-c M-m E |
Fully expand the macro at point, inline in the source buffer. |
|
C-c M-m b |
Run an inline-style macro-stepping session in a dedicated popup buffer. |
|
C-c C-v n |
Eval the ns form. If invoked with a prefix argument, undefine all vars and aliases in the ns first. |
|
C-c M-n (M-)n |
Switch the namespace of the REPL buffer to the namespace of the current buffer. |
|
C-c C-z |
Switch to the relevant REPL buffer. Use a prefix argument to change the namespace of the REPL buffer to match the currently visited source file. |
|
C-u C-u C-c C-z |
Switch to the REPL buffer based on a user prompt for a directory. |
|
C-c M-z |
Load (eval) the current buffer and switch to the relevant REPL buffer. Use a prefix argument to change the namespace of the REPL buffer to match the currently visited source file. |
|
C-c M-d |
Display default REPL connection details, including project directory name, buffer namespace, host and port. |
|
C-c C-o |
Clear the last output in the REPL buffer. With a prefix argument it will clear the entire REPL buffer, leaving only a prompt. Useful if you’re running the REPL buffer in a side by side buffer. |
|
C-c C-k |
Load (eval) the current buffer. If invoked with a prefix argument, undefine all vars and aliases in the ns before loading. |
|
C-c C-l |
Load (eval) a Clojure file. If invoked with a prefix argument, undefine all vars and aliases in the ns before loading. |
|
C-c C-M-l |
Load (eval) all Clojure files below a directory. If invoked with a prefix argument, undefine all vars and aliases in each file before loading. |
|
C-c M-n (M-)r |
Reload all modified files on the classpath. If invoked with a prefix argument, reload all files on the classpath. If invoked with a double prefix argument, clear the state of the namespace tracker before reloading. |
|
C-c C-d d |
Display doc string for the symbol at point. If invoked with a prefix argument it inverts the value of |
|
C-c C-d j |
Display JavaDoc (in your default browser) for the symbol at point. If invoked with a prefix argument it inverts the value of |
|
C-c C-d c |
Lookup symbol in ClojureDocs. If invoked with a prefix argument it inverts the value of |
|
C-c C-d w |
Open the ClojureDocs documentation for symbol in a web browser. If invoked with a prefix argument it inverts the value of |
|
C-c C-d a |
Apropos search for functions/vars. |
|
C-c C-d f |
Apropos search for documentation. |
|
C-c C-d e |
Apropos search for documentation & select. |
|
C-c M-i |
Inspect expression. Will act on expression at point if present. |
|
C-c M-t v |
Toggle var tracing. If invoked with a prefix argument it inverts the value of |
|
C-c M-t n |
Toggle namespace tracing. |
|
C-c C-u |
Undefine a symbol. If invoked with a prefix argument it inverts the value of |
|
C-c C-M-u |
Undefine all symbols and aliases in the namespace. |
|
C-c C-t t |
Run test at point. If the form under the point is a function, try to search and run a corresponding test. |
|
C-c C-t a |
Re-run the last test you ran. |
|
C-c C-t n |
Run tests for current namespace. |
|
C-c C-t l |
Run tests for all loaded namespaces. |
|
C-c C-t p |
Run tests for all project namespaces. This loads the additional namespaces. |
|
C-c C-t r |
Re-run test failures/errors. |
|
C-c C-t b |
Show the test report buffer. |
|
M-. |
Jump to the definition of a symbol. If invoked with a prefix argument it inverts the value of |
|
C-c C-: |
Find the namespace of the keyword at point and its primary occurrence there. If invoked with a prefix argument it inverts the value of |
|
mouse-5 or mouse-9 |
Jump to the definition of a symbol using mouse. |
|
mouse-4 or mouse-8 |
Jump back to where |
|
C-c M-. |
Jump to the resource referenced by the string at point. |
|
C-c C-. |
Jump to some namespace on the classpath. |
|
C-c C-? r |
Display function usages across loaded namespaces in a dedicated buffer. |
|
C-c C-? C-r |
Display function usages across loaded namespaces in a minibuffer selector. |
|
C-c C-? s |
Display function usages found by searching the project’s source files. |
|
C-c C-? d |
Display function deps (other functions used by it) in a dedicated buffer. |
|
C-c C-? C-d |
Display function deps (other functions used by it) in a minibuffer selector. |
|
C-c C-w c (also C-c C-? R) |
Browse a function’s callers as an expandable call-graph tree. |
|
C-c C-w d (also C-c C-? D) |
Browse a function’s callees as an expandable call-graph tree. |
|
C-c C-w m |
Find a macro’s use sites by searching the project’s source. |
|
C-c C-w i |
Browse a protocol’s implementing types or a multimethod’s dispatch values. |
|
C-c C-w t |
Browse the protocols a type implements. |
|
C-c C-w p |
Browse the protocols that declare a given method. |
|
M-, |
Return to your pre-jump location. |
|
M-TAB |
Complete the symbol at point. |
|
C-c C-q |
Quit the current nREPL connection. |
|
There’s no need to memorize this list. If you’re in a Clojure buffer with
An even better solution would be to install which-key, which will automatically show you a list of available keybindings as you start typing some keys. This will simplify your interactions with CIDER quite a lot, especially in the beginning. Here’s what you’d see if you typed C-c C-d in a Clojure buffer:
|
Deprecated Keybindings
As CIDER’s command set grows, some keybindings get reorganized - usually moved under a prefix group (like the documentation commands under C-c C-d). When that happens the old binding isn’t yanked away immediately: it keeps working for a deprecation window, but the first time you use it in a session it prints a one-time hint pointing at the replacement.
List everything currently deprecated, and what to use instead, with:
M-x cider-list-deprecated-keybindings
The old bindings keep working regardless; to silence the hints set:
(setq cider-warn-on-deprecated-keybindings nil)
For example, the REPL-only jack-in/connect keys C-c M-j, C-c M-J, C-c M-c and C-c M-C have been superseded by the shared C-c C-x start map (C-c C-x j j, C-c C-x j s, C-c C-x c j, C-c C-x c s) since 0.18.0, so they now warn when used.