Neovim Setup for Clojure

2 minute read

Neovim Setup for Clojure

I am a big fan of Neovim so I will be altering my setup to make it easy and convenient for me to program in Clojure.

LSP

For my LSP I am using the built in neovim lsp and williamboman/nvim-lsp-installer to install them. For Clojure I am using clojure-lsp.

 1-- In lsp-installer.lua
 2local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
 3if not status_ok then
 4	return
 5end
 6lsp_installer.setup {}
 7
 8local o = require('user.lsp.handlers').on_attach
 9local c = require('user.lsp.handlers').capabilities
10
11local lspconfig = require('lspconfig')
12
13lspconfig.clojure_lsp.setup {
14    on_attach = o
15    capabilites = c
16  }

Plugins

Plugins that I find useful

Including that in my Neovim config that uses Packer looks like this

 1return packer.startup(function(use)
 2  -- ...
 3
 4  use "Olical/conjure"
 5  use "tpope/vim-dispatch"
 6  use "radenling/vim-dispatch-neovim"
 7  use "clojure-vim/vim-jack-in"
 8
 9  -- ...
10)

Conjure

With conjure I can evaluate Clojure code in Neovim by using handy shortcuts. It works by evaluating Clojure code in spawned nREPL sever. This comes pretty handy because working with Clojure involves REPL a lot. Here is the basic overview of conjure keybinds

<localleader>ls   -  Open log buffer in horizontal split window. 
<localleader>lv   -  Open log buffer in vertical split window.
<localleader>E    -  Evaluate visual mode selection.
<localleader>ee   -  Evaluate the form under the cursor.
<localleader>ece  -  Evaluate the form under the cursor and display the result as a comment.
<localleader>er   -  Evaluate the root form under the cursor.
<localleader>ecr  -  Evaluate the root form under the cursor and display the result as a comment.

Vim Dispatch and Vim Jack In

Vim Dispatch is a tool used to spawn asynchronous tasks to build or test code in the background. I will be using it in conjuction with Vim Jack In to provide a REPL inside my Neovim setup. The only commands for working with Clojure are:

:Clj [args]  - for working with clj
:Lein [args] - for working with lein

I will primarily be using Leiningen for managing my Clojure projects.

Workflow

Example workflow for working with Clojure projects in Neovim would include:

  • setting up Conjure and Vim Jack In by executing :Lein
  • using Conjure to execute my code in REPL