sbdchd / neoformat

:sparkles: A (Neo)vim plugin for formatting code.
BSD 2-Clause "Simplified" License
1.97k stars 187 forks source link

Configuration on neovim use lua #479

Open EiEddie opened 9 months ago

EiEddie commented 9 months ago

I only see the configuration which use vimscript, but if I want to use this plugin in neovim, how I write a new conf which use lua? Or how I use the vimscript one in neovim?

P1n3appl3 commented 8 months ago

neoformat works just fine in neovim. If you're wondering how to configure it using lua, the options listed in :h neoformat-config are global vimscript variables (:h g:) which you can use from lua as follows:

-- defining a custom formatter in lua
vim.g.neoformat_typst_typstfmt = { exe = "typstfmt", replace = 1 }
vim.g.neoformat_enabled_typst = { "typstfmt" }

For more information about how this works, see :h lua-vim-variables and :h lua-vimscript. You can also write vimscript inline in your lua config, so something like the following would work:

vim.cmd [[
    let g:neoformat_basic_format_retab = 1
    let g:neoformat_try_node_exe = 1
]]

Note to maintainers: maybe it's worth adding a note about this in the README?