Skip to content

[idea] Auto-format on save with toggle #32

Closed

Description

@stanfish06

What

Add an opt-in auto-format-on-save autocmd backed by conform, with a buffer-local toggle command so it can be disabled per-file when needed.

Where

lua/config/plugin_config.lua — alongside the existing conform setup block.

Why it matters

The config already has <leader>lf for manual formatting and a full conform setup with per-filetype formatters (stylua, ruff_format, prettier). The missing piece is automatic formatting on write. A global always-on auto-format can be disruptive (e.g., linting noise in files you don't own), so a toggle is important.

Sketch

-- inside the conform setup block
vim.g.autoformat = true

vim.api.nvim_create_autocmd("BufWritePre", {
    callback = function(ev)
        if vim.g.autoformat then
            conform.format({ bufnr = ev.buf })
        end
    end,
})

vim.api.nvim_create_user_command("ToggleAutoFormat", function()
    vim.g.autoformat = not vim.g.autoformat
    vim.notify("Auto-format: " .. (vim.g.autoformat and "on" or "off"))
end, {})

Could also expose it as a statusline indicator (shows [fmt] when enabled) given the custom statusline is already in place.

Activity

  1. stanfish06 commented on Jul 26, 2026

    @stanfish06
    OwnerAuthor

    Already implemented: conform format-on-save with a toggle exists in plugin_config.lua (auto_format flag + BufWritePre). Duplicate of #147 and of the already-closed #205.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions