57 lines
1.8 KiB
Lua
57 lines
1.8 KiB
Lua
-- ============================================================
|
|
-- SECTION 6: FORMATTING
|
|
-- conform.nvim setup and keymap
|
|
-- ============================================================
|
|
do
|
|
-- [[ Formatting ]]
|
|
vim.pack.add { gh 'stevearc/conform.nvim' }
|
|
|
|
-- Formatters are grouped by profile; see the switches in init.lua
|
|
local formatters_by_ft = {
|
|
bash = { 'shfmt' },
|
|
sh = { 'shfmt' },
|
|
zsh = { 'shfmt' },
|
|
lua = { 'stylua' },
|
|
}
|
|
|
|
if vim.g.load_devops then
|
|
formatters_by_ft.nix = { 'nixfmt' }
|
|
formatters_by_ft.terraform = { 'terraform_fmt' }
|
|
formatters_by_ft.yaml = { 'yamlfmt' }
|
|
end
|
|
|
|
if vim.g.load_development then
|
|
formatters_by_ft.python = { 'black', 'isort' }
|
|
formatters_by_ft.c = { 'clang-format' }
|
|
formatters_by_ft.cpp = { 'clang-format' }
|
|
formatters_by_ft.kotlin = { 'ktfmt' }
|
|
end
|
|
|
|
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 = formatters_by_ft,
|
|
}, function()
|
|
vim.keymap.set({ 'n', 'v' }, '<leader>f', function() require('conform').format { async = true } end, { desc = '[F]ormat buffer' })
|
|
end)
|
|
end
|