Skip to content

Instantly share code, notes, and snippets.

@jteneycke
Created March 26, 2013 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jteneycke/5247692 to your computer and use it in GitHub Desktop.
Save jteneycke/5247692 to your computer and use it in GitHub Desktop.

Keyboard shortcuts

  • M-x nrepl-jack-in: Launch an nrepl server and a repl client. Prompts for a project root if given a prefix argument.
  • M-x nrepl: Connect to an already-running nrepl server.

While you're in clojure-mode, nrepl-jack-in is bound for convenience to C-c M-j and nrepl is bound to C-c M-c.

Clojure buffer commands:

Keyboard shortcut Description
C-x C-e Evaluate the form preceding point and display the result in the echo area. If invoked with a prefix argument, insert the result into the current buffer.
C-c C-p Evaluate the form preceding point and display the result in a popup buffer.
C-M-x C-c C-c Evaluate the top level form under point and display the result in the echo area. If invoked with a prefix argument, insert the result into the current buffer.
C-c C-r Evaluate the region and display the result in the echo area.
C-c C-b Interrupt any pending evaluations.
C-c C-m Invoke macroexpand-1 on the form at point and display the result in a macroexpansion buffer. If invoked with a prefix argument, macroexpand is used instead of macroexpand-1.
C-c M-m Invoke clojure.walk/macroexpand-all on the form at point and display the result in a macroexpansion buffer.
C-c C-n Eval the ns form.
C-c M-n Switch the namespace of the repl buffer to the namespace of the current buffer.
C-c C-z Select the REPL buffer. With a prefix argument - changes the namespace of the REPL buffer to the one of the currently visited source file.
C-c M-o 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 the current buffer.
C-c C-l Load a file.
C-c C-d Display doc string for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
C-c C-s Display the source for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
C-c C-j Display JavaDoc (in your default browser) for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
M-. Jump to the definition of a symbol. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
M-, Return to your pre-jump location.
M-TAB Complete the symbol at point. (For auto-complete integration, see ac-nrepl)

REPL buffer commands:

Keyboard shortcut Description
RET Evaluate the current input in Clojure if it is complete. If incomplete, open a new line and indent. If invoked with a prefix argument is given then the input is evaluated without checking for completeness.
C-RET Close any unmatched parenthesis and then evaluate the current input in Clojure.
C-j Open a new line and indent.
C-c M-o Clear the entire REPL buffer, leaving only a prompt.
C-c C-o Remove the output of the previous evaluation from the REPL buffer.
C-c C-u Kill all text from the prompt to the current point.
C-c C-b C-c C-c Interrupt any pending evaluations.
C-up C-down Goto to previous/next input in history.
M-p M-n Search the previous/next item in history using the current input as search pattern. If M-p/M-n is typed two times in a row, the second invocation uses the same search pattern (even if the current input has changed).
M-s M-r Search forward/reverse through command history with regex.
C-c C-n C-c C-p Move between the current and previous prompts in the REPL buffer. Pressing RET on a line with old input copies that line to the newest prompt.
TAB Complete symbol at point.
C-c C-d Display doc string for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol
C-c C-j Display JavaDoc (in your default browser) for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.

Macroexpansion buffer commands:

Keyboard shortcut Description
C-c C-m Invoke macroexpand-1 on the form at point and replace the original form with its expansion. If invoked with a prefix argument, macroexpand is used instead of macroexpand-1.
C-c M-m Invoke clojure.walk/macroexpand-all on the form at point and replace the original form with its expansion.
g The prior macroexpansion is performed again and the current contents of the macroexpansion buffer are replaced with the new expansion.
C-/ C-x u Undo the last inplace expansion performed in the macroexpansion buffer.

Managing multiple sessions

You can connect to multiple nREPL servers and use M-x nrepl-jack-in multiple times. To close a single nREPL session, use M-x nrepl-close. M-x nrepl-quit closes all sessions.

nrepl.el commands in a clojure buffer use the default connection. To make a connection default, switch to it's repl buffer and use M-x nrepl-make-repl-connection-default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment