Closed tf42src closed 3 months ago
Formatting, also gives some configuration options: opts and I kind of understand that I need to add sth. like html = {"prettier"} to formatters_by_ft. Makes sense, but where? I cannot find conform.nvim anywhere in my .config/nvim/ folder except for one entry in ./lazy-lock.json. I followed this well-explained youtube video to enable formatting which lead to "Don't override plugin.config directly, since this will break LazyVim formatting."
It's mentioned in the docs where you should place your own customization right here. So you just create a file in /lua/plugins/
directory and inside the file you make the changes you want for the specific plugin spec you're interested in. So, you would do something like
return {
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
["html"] = { "prettier" },
},
},
},
}
I also tried copying the "Full Spec" from Formatting into a new file in my plugins directory which also didn't work (the built-in lua LSP hinted at all sorts of errors).
You should never copy the entire from what's in the docs. Usually there's a warning about this in the docs, but for some reason in the formatting page it's missing.
caution You don't need to copy the default settings to your config. They are only shown here for reference.
So, in summary, you create files in ~/.config/nvim/lua/plugins/
directory and there you make changes to the specs of the plugins you want to change, as is mentioned in the docs.
Thanks for the quick reply! I have added the "opts" in my plugin directory like this:
(I have removed the "format_on_save" again - because that wasn't allowed). Nevertheless, navigating to an html file and pressing <leader>cf
still shows, I don't have a formatter:
I have double checked, that prettier
is installed.
The only hint I could find was this (but it doesn't tell me what the error is):
cat ~/.local/state/nvim/conform.log
01:23:21[ERROR] Formatter 'prettier' error:
01:23:38[ERROR] Formatter 'prettier' error:
01:23:40[ERROR] Formatter 'prettier' error:
01:23:45[ERROR] Formatter 'prettier' error:
I can run prettier manually and it works:
~/node_modules/.bin/prettier ~/projects/testproj/intro.html
Did a bit more digging and found this, which made me check what I have installed, but everything looks fine:
What does :!which prettier
show inside Neovim?
I can execute prettier
directly from the command line too (it's added to $PATH
).
What does LazyFormatInfo
and ConformInfo
show?
Did you check the docs?
Is your feature request related to a problem? Please describe.
I am trying to format html. It is not fully clear to me what the required steps are. Do I need to install conform.nvim? Do I need to install a language server, do I need to have npm, do I need prettier?
I started with the StarterTemplate which works great. I am really enjoying it and I am getting used more and more how to use everything. What I couldn't figure out so far what steps do I need to do to enable formatting (on save and on shortcut) for html.
<leader>cf
(while a html file is open) currently gives me "No formatter available". So I head over to Formatting which tells me I should useconform.nvim
- which seems to be installed (see screenshot).Formatting, also gives some configuration options:
opts
and I kind of understand that I need to add sth. likehtml = {"prettier"}
toformatters_by_ft
. Makes sense, but where?I cannot find
conform.nvim
anywhere in my.config/nvim/
folder except for one entry in./lazy-lock.json
. I followed this well-explained youtube video to enable formatting which lead to "Don't override plugin.config directly, since this will break LazyVim formatting."I also tried copying the "Full Spec" from Formatting into a new file in my plugins directory which also didn't work (the built-in lua LSP hinted at all sorts of errors).
Apologies for the lengthy description, but hopefully it makes it a bit clear what a new user of lazyvim might go through and struggle with.
Describe the solution you'd like
A simple example how/where to enable formatting for anything but what is enabled already.
Describe alternatives you've considered
Youtube :)
Additional context