vim.keymap.set("n", "P", "ConformProject", { noremap = true, silent = true }) vim.api.nvim_create_user_command("ConformProject", function() local conform = require("conform") local root = vim.fn.getcwd() -- Use git to get files (respects .gitignore) local handle = io.popen(string.format("cd %s && git ls-files --cached --others --exclude-standard", root)) if not handle then vim.notify("Failed to scan project files", vim.log.levels.ERROR) return end local files = {} for file in handle:lines() do table.insert(files, vim.fn.fnamemodify(file, ":p")) end handle:close() -- Format each file local formatted_count = 0 for _, filepath in ipairs(files) do local bufnr = vim.fn.bufadd(filepath) vim.fn.bufload(bufnr) local ok, err = conform.format({ bufnr = bufnr }) if ok then formatted_count = formatted_count + 1 -- Save the buffer vim.api.nvim_buf_call(bufnr, function() vim.cmd("write") end) end end vim.notify(string.format("Formatted %d files", formatted_count), vim.log.levels.INFO) end, {}) -- docs -> https://github.com/stevearc/conform.nvim return { { "conform.nvim", enabled = nixCats("format") or false, keys = { { "p", desc = "Format File (pretty :3)" }, }, after = function(plugin) local conform = require("conform") conform.setup({ formatters_by_ft = { lua = nixCats("lang.lua") and { "stylua" } or nil, nix = nixCats("lang.nix") and { "alejandra" } or nil, rust = nixCats("lang.rust") and { "rustfmt", lsp_format = "fallback" } or nil, haskell = nixCats("lang.haskell") and { "ormolu" } or nil, proto = nixCats("lang.protobuf") and { "buf" } or nil, }, format_on_save = { timeout_ms = 500, }, }) vim.keymap.set({ "n", "v" }, "p", function() conform.format({ lsp_fallback = false, async = false, timeout_ms = 1000, }) end, { desc = "Format File (pretty :3)" }) end, }, }