Migrated init.lua into plugin files
This commit is contained in:
49
AppData/Local/nvim/lua/plugins/conform.lua
Normal file
49
AppData/Local/nvim/lua/plugins/conform.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
return {
|
||||
{ -- Autoformat
|
||||
'stevearc/conform.nvim',
|
||||
event = { 'BufWritePre' },
|
||||
cmd = { 'ConformInfo' },
|
||||
keys = {
|
||||
{
|
||||
'<leader>f',
|
||||
function()
|
||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
||||
end,
|
||||
mode = '',
|
||||
desc = '[F]ormat buffer',
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
local conform = require 'conform'
|
||||
|
||||
conform.setup {
|
||||
notify_on_error = false,
|
||||
format_on_save = function(bufnr)
|
||||
local disable_filetypes = { c = true, cpp = true, vue = true }
|
||||
if disable_filetypes[vim.bo[bufnr].filetype] then
|
||||
return nil
|
||||
else
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
lsp_format = 'fallback',
|
||||
}
|
||||
end
|
||||
end,
|
||||
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
--xml = { 'xmlformatter' }, -- USE CUSTOM FORMATTER
|
||||
python = { 'black', 'isort' },
|
||||
json = { 'prettierd' },
|
||||
},
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
pattern = '*',
|
||||
callback = function(args)
|
||||
require('conform').format { bufnr = args.buf, lsp_fallback = true }
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user