How to disable autoformat on save for specific language #2130
Replies: 2 comments 1 reply
-
|
Should post on https://github.com/LazyVim/LazyVim/discussions
Try
I don't think
It's not related to lsp, the language server is ignorant about either your config or lua pattern.
Lazy loading only specific to plugin loading, not your isolated autocmds Anyway, here's a tip you may need for a temporary workaround. vim.lsp.config('verible', {
on_attach = function(client)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
client.server_capabilities.documentOnTypeFormattingProvider = nil
end,
}) |
Beta Was this translation helpful? Give feedback.
-
|
@sharpchen thank you so much for the help! For anyone else who is stuck on this, the message board here has a solution that worked for me. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to disable auto format on save for a specific language (verilog using verible) but am having trouble. I add the following code to my options.lua and autocommand.lua (I've tried both places) and have had no luck.
-- Example: Disable auto-formatting for specific file types vim.api.nvim_create_autocmd("FileType", { print("Hello from autocmd.lua"), pattern = { "verilog", "Verilog", "v", "sv" }, callback = function() local filetype = vim.bo.filetype -- Skip autoformatting for specified file types if vim.tbl_contains({ "fish", "lua", "perl", "yaml" }, filetype) then vim.b.autoformat = false return end -- Apply autoformatting for other file types vim.b.autoformat = true end, group = vim.api.nvim_create_augroup("disable_autoformat", { clear = true }), })I even stuck a print hello world message in there to see if it was working. I noticed when I open a verilog file with neo-tree I don't see the message and the autof ormatting on save is not disabled.
When I open an example verilog file from the command line using I see my hello world message but auto formatting on save still works - it is not disabled like I would expect.
I also noticed that verible might now support lua patterns:

My configuration is a fresh neovim install and then I followed the instructions to clone and run lazy.nvim. I have not modified a single thing. I'm using neovim 0.11.6 and the latest lazy.nvim posted on the website.
So I guess my questions are:
In case the code I posted isn't readable I've attached a screenshot of autocmds.lua:

Any advice is greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions