From 16f2dbbe3de31c40c4a8a71b906092d9e81c1bdf Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Wed, 13 Aug 2025 12:10:58 +0200 Subject: [PATCH] Fix keymaps and fold --- lazyvim/.config/nvim/lua/config/autocmds.lua | 29 ++++++++++++++++++++ lazyvim/.config/nvim/lua/config/keymaps.lua | 12 ++------ lazyvim/.config/nvim/lua/config/options.lua | 5 ---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lazyvim/.config/nvim/lua/config/autocmds.lua b/lazyvim/.config/nvim/lua/config/autocmds.lua index 27e9e06..b976b59 100644 --- a/lazyvim/.config/nvim/lua/config/autocmds.lua +++ b/lazyvim/.config/nvim/lua/config/autocmds.lua @@ -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, +}) diff --git a/lazyvim/.config/nvim/lua/config/keymaps.lua b/lazyvim/.config/nvim/lua/config/keymaps.lua index 1c1a170..33004ad 100644 --- a/lazyvim/.config/nvim/lua/config/keymaps.lua +++ b/lazyvim/.config/nvim/lua/config/keymaps.lua @@ -9,17 +9,11 @@ map("n", "bn", ":bnext", { noremap = true, silent = true, desc = "Ne map("n", "bp", ":bprevious", { noremap = true, silent = true, desc = "Previous buffer" }) map("n", "bd", ":bdelete", { noremap = true, silent = true, desc = "Delete buffer" }) --- Window navigation (splits) -map("n", "sh", "h", { noremap = true, silent = true, desc = "Window left" }) -map("n", "sj", "j", { noremap = true, silent = true, desc = "Window down" }) -map("n", "sk", "k", { noremap = true, silent = true, desc = "Window up" }) -map("n", "sl", "l", { noremap = true, silent = true, desc = "Window right" }) - --- Quick save -map("n", "w", ":w", { noremap = true, silent = true, desc = "Save file" }) - -- Copy to system clipboard (if not already mapped) map({ "n", "v" }, "y", [["+y]], { noremap = true, silent = true, desc = "Copy to system clipboard" }) -- Paste from system clipboard map("n", "p", [["+p]], { noremap = true, silent = true, desc = "Paste from system clipboard" }) + +-- Markdown menu +map("n", "M", [["+M]], { noremap = true, silent = true, desc = "Markdown" }) diff --git a/lazyvim/.config/nvim/lua/config/options.lua b/lazyvim/.config/nvim/lua/config/options.lua index 5290600..1e8d5fc 100644 --- a/lazyvim/.config/nvim/lua/config/options.lua +++ b/lazyvim/.config/nvim/lua/config/options.lua @@ -45,11 +45,6 @@ opt.statusline = "%f %m %r %=%-14.(%l,%c%V%) %P" -- Persistent signcolumn to avoid text shifting opt.signcolumn = "yes" --- Fold method -opt.foldmethod = "expr" -opt.foldexpr = "nvim_treesitter#foldexpr()" -opt.foldlevel = 99 -- open all folds by default - -- Show file name and modified flag in the window bar opt.winbar = "%=%m %f"