add autoformatting with Python

This commit is contained in:
Eric Tiedemann 2023-11-25 21:46:09 -05:00
parent 25a94d9353
commit 743c03a1b6
3 changed files with 29 additions and 1 deletions

10
lua/autocmds.lua Normal file
View file

@ -0,0 +1,10 @@
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = { "*.py" },
desc = "Auto-format Python files after saving",
callback = function()
local fileName = vim.api.nvim_buf_get_name(0)
vim.cmd(":silent !black --preview -q " .. fileName)
vim.cmd(":silent !isort --profile black --float-to-top -q " .. fileName)
end,
group = autocmd_group,
})