REPL Configuration

Behavior on connect

Normally, when you first establish a REPL connection, the REPL buffer is auto-displayed in a separate window. You can suppress this behaviour like this:

(setq cider-repl-pop-to-buffer-on-connect nil)

If you want the REPL buffer to be auto-displayed, but don’t want it to be focused, use this:

(setq cider-repl-pop-to-buffer-on-connect 'display-only)

Behavior on switch

By default C-c C-z will display the REPL buffer in a different window. You can make C-c C-z switch to the CIDER REPL buffer in the current window:

(setq cider-repl-display-in-current-window t)

Customizing the REPL prompt

You can customize the REPL buffer prompt by setting cider-repl-prompt-function to a function that takes one argument, a namespace name. For convenience, CIDER provides three functions that implement common formats:

  • cider-repl-prompt-lastname:

  • cider-repl-prompt-abbreviated:

  • cider-repl-prompt-default:


By default, CIDER uses cider-repl-prompt-default.

You may, of course, write your own function. For example, in leiningen there are two namespaces with similar names - leiningen.classpath and leiningen.core.classpath. To make them easily recognizable you can either use the default value or you can opt to show only two segments of the namespace and still be able to know which is the REPL’s current namespace. Here is an example function that will do exactly that:

(defun cider-repl-prompt-show-two (namespace)
  "Return a prompt string with the last 2 segments of NAMESPACE."
  (let ((names (reverse (subseq (reverse (split-string namespace "\\.")) 0 2))))
    (concat (car names) "." (cadr names) "> ")))

TAB Completion

You can control the TAB key behavior in the REPL using the cider-repl-tab-command variable. While the default command cider-repl-indent-and-complete-symbol should be an adequate choice for most users, it’s very easy to switch to another command if you wish to. For instance if you’d like TAB to only indent (maybe because you’re used to completing with M-TAB) use the following:

(setq cider-repl-tab-command #'indent-for-tab-command)

Auto-scrolling the REPL on Output

Prior to version 0.21.0, the REPL buffer would be automatically re-centered whenever any output was printed, so that the prompt was on the bottom line of the window, displaying the maximum possible amount of output above it. This is no longer the default behaviour — you can now replicate it by setting the built-in option scroll-conservatively, for example:

(add-hook 'cider-repl-mode-hook '(lambda () (setq scroll-conservatively 101)))

Result Prefix

You can change the string used to prefix REPL results:

(setq cider-repl-result-prefix ";; => ")

Which then results in the following REPL output:

user> (+ 1 2)
;; => 3

By default, REPL results have no prefix.

Customize the REPL Buffer’s Name

You can customize the buffer name using the variable cider-session-name-template. See the documentation for this variable for details.


Normally, code in the REPL is font-locked the same way as in clojure-mode. Before CIDER 0.10, by default, REPL input was font-locked with cider-repl-input-face (after pressing Return) and results were font-locked with cider-repl-result-face. If you want to restore the old behaviour use:

(setq cider-repl-use-clojure-font-lock nil)

Note that enabling font-locking in the REPL can negatively impact performance.

Pretty printing in the REPL

By default the REPL always prints the results of your evaluations using the printing function specified by cider-print-fn.

This behaviour was changed in CIDER 0.20. In prior CIDER releases pretty-printing was disabled by default.

You can temporarily disable this behaviour and revert to the default behaviour (equivalent to clojure.core/pr) using M-x cider-repl-toggle-pretty-printing.

If you want to disable using cider-print-fn entirely, use:

(setq cider-repl-use-pretty-printing nil)

Note that disabling pretty-printing is not advised. Emacs does not handle well very long lines, so using a printing function that wraps lines beyond a certain width (i.e. any of them except for pr) will keep your REPL running smoothly.

See this for more information on configuring printing.

Displaying images in the REPL

Starting with CIDER 0.17 (AndalucĂ­a) expressions that evaluate to images will be rendered as images in the REPL. You can disable this behavior if you don’t like it.

(setq cider-repl-use-content-types nil)

Alternatively, you can toggle this behaviour on and off using M-x cider-repl-toggle-content-types.

Customizing the initial REPL namespace

Normally, the CIDER REPL will start in the user namespace. You can supply an initial namespace for REPL sessions in the repl-options section of your Leiningen project configuration:

:repl-options {:init-ns 'my-ns}

Customizing newline interaction

Ordinarily, Return immediate sends a form for evaluation. If you want to insert a newline into the REPL buffer as you’re editing, you can do so using C-j. If you are entering a lot of longer forms that span multiple lines, it may be more convenient to change the keybindings:

(define-key cider-repl-mode-map (kbd "RET") #'cider-repl-newline-and-indent)
(define-key cider-repl-mode-map (kbd "C-<return>") #'cider-repl-return)

This will make Return insert a newline into the REPL buffer and C-Return send the form off for evaluation.

REPL history

  • To make the REPL history wrap around when CIDER reaches the end:

(setq cider-repl-wrap-history t)
  • To adjust the maximum number of items kept in the REPL history:

(setq cider-repl-history-size 1000) ; the default is 500
  • To store the REPL history in a file:

(setq cider-repl-history-file "path/to/file")

Note that CIDER writes the history to the file when you kill the REPL buffer, which includes invoking cider-quit, or when you quit Emacs.

Set ns in REPL

By default cider-repl-set-ns won’t require the target ns, just set it. That’s done with the assumption that you’ve probably evaluated the ns in question already before switching to it (e.g. by doing C-c C-k in its source file). If you want to change this behaviour (to avoid calling cider-repl-set-ns and then (require 'my-ns) manually), you can set:

(setq cider-repl-require-ns-on-set t)

Control what window to use when jumping to a definition

By default M-. and other commands that jump to a definition have the following behaviour:

  • If the definition buffer is visible simply switch to it.

  • Otherwise, use the current window to show the definition.

Other behaviour is possible, and is controlled with cider-jump-to-pop-to-buffer-actions; the value of this is passed as the action argument to pop-to-buffer.

The default value is ((display-buffer-reuse-window display-buffer-same-window)).

Some people might prefer to always display the definition in the current window. Here’s how you can achieve this:

(setq cider-jump-to-pop-to-buffer-actions
Keep in mind this might cause problems with some special buffers (e.g. test report buffers), as when you try to navigate to a definition this will clobber the special buffer.

For other possibilities, see the documentation for display-buffer.

Example 1

You jump to map in core.clj when core.clj is not being displayed in another window in the current frame.

With both the default behaviour and the alternative behaviour defined above, the definition of map will be shown in the current window.

Example 2

You jump to map in core.clj when core.clj is being displayed in another window in the current frame.

With the default behaviour, the definition of map will be shown in the current window; you will now have two windows showing core.clj, and the existing core.clj window will be unchanged.

With the alternative behaviour defined above, the definition of map will be shown in the existing core.clj window; all windows will show the same buffer as before the jump, and the current window will now be the one showing core.clj.