Files
NeovimConfig/lua/formatting.lua
T
2026-10-29 11:26:24 +01:00

47 lines
1.6 KiB
Lua

-- ============================================================
-- SECTION 6: FORMATTING
-- conform.nvim setup and keymap
-- ============================================================
do
-- [[ Formatting ]]
vim.pack.add { gh 'stevearc/conform.nvim' }
safe_require('conform', {
notify_on_error = true,
format_after_save = {
lsp_fallback = true,
timeout_ms = 500,
},
-- format_on_save = function(bufnr)
-- -- You can specify filetypes to autoformat on save here:
-- local enabled_filetypes = {
-- -- lua = true,
-- -- python = true,
-- }
-- if enabled_filetypes[vim.bo[bufnr].filetype] then
-- return { timeout_ms = 500 }
-- else
-- return nil
-- end
-- end,
default_format_opts = {
lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely.
},
-- You can also specify external formatters in here.
formatters_by_ft = {
bash = { 'shfmt' },
sh = { 'shfmt' },
zsh = { 'shfmt' },
python = { 'black', 'isort' },
lua = { 'stylua' },
c = { 'clang-format' },
cpp = { 'clang-format' },
kotlin = { 'ktfmt' },
--
-- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true },
},
}, function()
vim.keymap.set({ 'n', 'v' }, '<leader>f', function() require('conform').format { async = true } end, { desc = '[F]ormat buffer' })
end)
end