From 41adc6ce763d7f195393d89720b49ce976cfee6e Mon Sep 17 00:00:00 2001 From: groveer Date: Mon, 18 Mar 2024 11:47:11 +0800 Subject: [PATCH] feat: restore cursor position from last time --- lua/nvchad/autocmds.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lua/nvchad/autocmds.lua b/lua/nvchad/autocmds.lua index 229237e..78c18f9 100644 --- a/lua/nvchad/autocmds.lua +++ b/lua/nvchad/autocmds.lua @@ -67,3 +67,19 @@ vim.api.nvim_create_autocmd({ "UIEnter", "BufReadPost", "BufNewFile" }, { end end, }) + +-- restore cursor position +autocmd("BufReadPost", { + pattern = "*", + callback = function() + local line = vim.fn.line "'\"" + if + line > 1 + and line <= vim.fn.line "$" + and vim.bo.filetype ~= "commit" + and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1 + then + vim.cmd 'normal! g`"' + end + end, +})