25 lines
637 B
Lua
25 lines
637 B
Lua
local group = vim.api.nvim_create_augroup("IndentFormatOnSave", { clear = true })
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
group = group,
|
|
callback = function(args)
|
|
local ft = vim.bo[args.buf].filetype
|
|
local indent_filetypes = {
|
|
c = true,
|
|
cpp = true,
|
|
h = true,
|
|
hpp = true,
|
|
}
|
|
|
|
if not indent_filetypes[ft] then
|
|
return
|
|
end
|
|
|
|
local view = vim.fn.winsaveview()
|
|
vim.api.nvim_buf_call(args.buf, function()
|
|
vim.cmd("silent keepjumps normal! gg=G")
|
|
end)
|
|
vim.fn.winrestview(view)
|
|
end,
|
|
})
|