Connect Conjure to an Existing nREPL Session

Here's how to connect an nvim buffer to an existing nrepl session.


nREPL is a Clojure REPL that is available in a client-server architecture. You might have an nrepl server started somewhere and want to connect your nvim session to it with Conjure.

Install Tools

Here using packer, we're putting a few nice nvim tools together to conveniently support the connection.

return require('packer').startup(function(use)
  -- ...
  use {
    'Olical/conjure', -- repl
    'tpope/vim-dispatch', -- kick off builds
    'radenling/vim-dispatch-neovim', -- add nvim terminal emulator and job control to dispatch.vim
    'clojure-vim/vim-jack-in', -- commands for clj, lein and boot
    ft = 'clojure'
  -- ...

Auto Connect

Most of the time, a new Conjure session should create a new nREPL session with auto-repl. It tries to detect previously-existing nrepl sessions. That might be indicated by an existing .nrepl-port file in the project root.

If you start Conjure and keep getting ECONNREFUSED and disconnected messages, you may have a .nrepl-port file hanging around that points to a port that's no longer available. (nREPL starts on random ports.) Delete the .nrepl-port file, and you should get auto-repl to start a new session.

Start nREPL from nvim

You can also start a new nrepl session from nvim using clojure-vim/vim-jack-in's command:


That'll start a new repl in a new tab, reporting that:

nREPL server started on port 42881 on host localhost - nrepl://localhost:42881

It puts you in a kind of terminal/insert mode. You can't get to normal mode with Esc, however. Use C-\C-n to get to normal mode, then gt to change tabs, as usual.

Connect to the Session

As in the last step, you know you have a session on port 42881, you can connect using this Olical/conjure command:

:ConjureConnect 42881

From there, you should be able to evaluate like a champ.