NVIM中使用不同格式的文件扩展程序的自动格式和缩进代码
我有一个可以自动保存文件的插件。该插件具有.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以安装 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.