Fix keymaps and fold

This commit is contained in:
Fabio Scotto di Santolo
2025-08-13 12:10:58 +02:00
parent b0d1bb1d73
commit 16f2dbbe3d
3 changed files with 32 additions and 14 deletions

View File

@@ -1,3 +1,32 @@
-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
-- Add any additional autocmds here
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
local view_group = augroup("auto_view", { clear = true })
autocmd({ "BufWinLeave", "BufWritePost", "WinLeave" }, {
desc = "Save view with mkview for real files",
group = view_group,
callback = function(args)
if vim.b[args.buf].view_activated then
vim.cmd.mkview({ mods = { emsg_silent = true } })
end
end,
})
autocmd("BufWinEnter", {
desc = "Try to load file view if available and enable view saving for real files",
group = view_group,
callback = function(args)
if not vim.b[args.buf].view_activated then
local filetype = vim.api.nvim_get_option_value("filetype", { buf = args.buf })
local buftype = vim.api.nvim_get_option_value("buftype", { buf = args.buf })
local ignore_filetypes = { "gitcommit", "gitrebase", "svg", "hgcommit" }
if buftype == "" and filetype and filetype ~= "" and not vim.tbl_contains(ignore_filetypes, filetype) then
vim.b[args.buf].view_activated = true
vim.cmd.loadview({ mods = { emsg_silent = true } })
end
end
end,
})