NVIM中使用不同格式的文件扩展程序的自动格式和缩进代码

发布于 2025-02-11 02:12:32 字数 331 浏览 1 评论 0原文

我有一个可以自动保存文件的插件。该插件具有.hook_before_saving等。 这是一个示例:

local autosave = require("autosave")

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

每次文件被自动保存时,我都想使用不同的格式(例如JavaScript或货物FMT)来生锈。

是否可以?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

庆幸我还是我 2025-02-18 02:12:32

您可以安装 formatter.nvim null-ls.nvim neovim插件根据FileType(您的情况下的Rust或JS)使用不同的格式化插件。

并调用命令通过挂钩中的插件来执行代码格式,以供自动执行文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文