Format Solidity files automatically on save or manually via :ForgeFmt β powered by forge fmt.
- π Single-file support β works even without a full Foundry project
- π Respects
foundry.tomlproject config β uses[fmt]settings fromfoundry.tomlif present - π‘ LSP-free β no language server required to format
- β¨ Autoformat on save β set it and forget it for
.solfiles - π― Manual formatting β use
:ForgeFmtanytime
return {
"mmsaki/forgefmt.nvim",
config = function()
require("forgefmt").setup({
auto_format = true, -- enable autoformat on save
-- Support for [`shafu`](https://github.com/shafu0x/shafu-formatter) Requires `shafu` to be available in your `$PATH`.
-- Shafu formatter support is still in early development and may produce unstable results.
-- Keep this false unless you want to try shafu
use_shafu = false,
})
end,
}Or load manually and call the command:
:ForgeFmtoptional re-mappings:
This is NOT a default re-mapping but an example
| Keys | Mode | Description |
|---|---|---|
| space β f | Normal | Forge Format |
return {
"mmsaki/forgefmt.nvim",
config = function()
require("forgefmt").setup({
auto_format = true, -- enable autoformat on save
})
vim.keymap.set("n", "<leader>f", ":ForgeFmt<CR>", { desc = "Forge Format" })
end,
}- Automatically formats
.solfiles on save (ifauto_format = true) - Or trigger manually via
:ForgeFmt - Compatible with both standalone Solidity files and Foundry projects
You can plug forgefmt.nvim into your existing LSP formatting pipeline using a custom formatter hook.
vim.api.nvim_create_autocmd("FileType", {
pattern = "solidity",
callback = function()
vim.lsp.buf.format = function()
require("forgefmt").format()
end
end,
})