Fork me on GitHub
#vim
<
2022-06-22
>
practicalli-john19:06:09

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 🙂

practicalli-john19:06:55

To change the comment string in vimscript seems to be

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

nbardiuk19:06:04

something like this in fennel

(vim.api.nvim_create_autocmd
  :FileType
  {: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

nbardiuk20:06:25

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

practicalli-john20:06:18

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.