1

I have a plugin that autosaves the file. This plugin has hooks like .hook_before_saving etc. Here is an example:

local autosave = require("autosave")

autosave.hook_before_saving = function ()
    if <condition> then
        vim.g.auto_save_abort = true -- Save will be aborted
    end
end

I would like to use different formaters like prettier for javascript or cargo fmt for rust every time the file is autosaved.

Is it possible?

1 Answer 1

1

You could install Formatter.nvim or null-ls.nvim Neovim plugin to use different formatters according to filetype (Rust or JS in your case).

And call command to execute code formatting via plugin in your hook for autosave file.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. You can see how I did it here github.com/Raduc4/Rust-nvim-IDE.git

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.