Fork me on GitHub

Using Lua (or fennel) for Neovim 0.7.0, I am trying to change the Clojure FileType commentstring to be ;; rather than what seems to be the default ; commentstring. Or at the very least have both ; and ;; recognised as a comment line. I’d like to use vim-commentry, or something similar to toggle comment lines, but it only recognises ; lines, so actually adds a third ; if I try to uncomment an existing line with ;; All my code is written with ;; as are my work colleagues, so changing all the comments is not a workable option… I am still learning Neovim and Lua (and fenel - that seems to be the easy bit), so assume I know nothing 🙂


To change the comment string in vimscript seems to be

augroup commentary_config
  autocmd FileType lisp,clojure,racket setlocal commentstring=;;\ %s
augroup END
But I dont know how to do this in Lua with Neovim…


something like this in fennel

  {:group (vim.api.nvim_create_augroup :commentary_config {:clear true})
   :pattern [:lisp :clojure :racket]
   :callback (fn [] (set vim.opt_local.commentstring ";; %s") nil)})
But I am not sure in which version of neovim those api calls where introduced


(au commentary_config :FileType [:lisp :clojure :racket]
  (set vim.opt_local.commentstring ";; %s"))


Excellent, I’ve tried the first code block you shared and it works perfectly. I’ll have a look at your dot files and if there are more autocmd things I need then I’ll adopt the macro you have written. The whole config you have shared looks very interesting, so I will spend some time looking through it to learn more about Neovim and fennel Thank you very much for sharing.