From a324726b736ec39b1fbb534eb7793ccdfaf428ec Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Tue, 30 Jun 2026 08:49:30 +0530 Subject: [PATCH] feat: Add persistence --- lazy-lock.json | 3 ++- lua/plugins/persistence.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 lua/plugins/persistence.lua diff --git a/lazy-lock.json b/lazy-lock.json index 6a1e1c4..a2cd3d4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -20,7 +20,7 @@ "mini.cursorword": { "branch": "main", "commit": "331bc17172e41343d39d91a4ab571d510766812e" }, "mini.indentscope": { "branch": "main", "commit": "d3f955f09b1a05d25d5a7740338fba2baaee41a3" }, "mini.move": { "branch": "main", "commit": "b9e452f9c83565a1520e14f7531632160f3b0170" }, - "mini.nvim": { "branch": "main", "commit": "1599a473aa6f5290a5d740b1144846e6f0c3963d" }, + "mini.nvim": { "branch": "main", "commit": "7c2caf0ae915d819f2f39467d6bb9313c2b3e90a" }, "mini.pairs": { "branch": "main", "commit": "4a014143fcb4e9df26198ccb3ecff3b9e77a048c" }, "mini.surround": { "branch": "main", "commit": "580e4cb98c5900d9fe743865fb5a5b2178b4ab18" }, "mini.tabline": { "branch": "main", "commit": "7e8584a06b86902c64227e4abd0c39ae74061101" }, @@ -31,6 +31,7 @@ "nvim-tree.lua": { "branch": "master", "commit": "85d1145ac71c1b8e1423862c78165a1f609faf60" }, "nvim-treesitter": { "branch": "main", "commit": "4916d6592ede8c07973490d9322f187e07dfefac" }, "nvim-web-devicons": { "branch": "master", "commit": "dfbfaa967a6f7ec50789bead7ef87e336c1fa63c" }, + "persistence.nvim": { "branch": "main", "commit": "b20b2a7887bd39c1a356980b45e03250f3dce49c" }, "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, "render-markdown.nvim": { "branch": "main", "commit": "f422cb5c6855f150e2ddcfaf44e7157b98b34f6a" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "b25b749b9db64d375d782094e2b9dce53ad53a40" }, diff --git a/lua/plugins/persistence.lua b/lua/plugins/persistence.lua new file mode 100644 index 0000000..f8d0854 --- /dev/null +++ b/lua/plugins/persistence.lua @@ -0,0 +1,29 @@ +return { + { + "folke/persistence.nvim", + lazy = false, + opts = { + -- Options (default values are standard) + }, + config = function(_, opts) + require("persistence").setup(opts) + + -- Automatically restore session when opening Neovim without arguments + vim.api.nvim_create_autocmd("VimEnter", { + group = vim.api.nvim_create_augroup("PersistenceAutoLoad", { clear = true }), + callback = function() + -- Only autoload if Neovim was launched with no arguments + if vim.fn.argc() == 0 then + -- Pre-load session if it exists for the current directory + require("persistence").load() + end + end, + }) + + -- Session keymaps + vim.keymap.set("n", "qs", function() require("persistence").load() end, { desc = "Restore Session" }) + vim.keymap.set("n", "ql", function() require("persistence").load({ last = true }) end, { desc = "Restore Last Session" }) + vim.keymap.set("n", "qd", function() require("persistence").stop() end, { desc = "Stop Session Saving (For exit)" }) + end, + }, +}