diff --git a/plugin/holtrop.lua b/plugin/holtrop.lua index cd9c084..3e8a4e7 100644 --- a/plugin/holtrop.lua +++ b/plugin/holtrop.lua @@ -43,6 +43,24 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, { end, }) +-- Restore cursor position after opening a file +local cursor_group = vim.api.nvim_create_augroup("holtrop_restore_cursor", { clear = true }) + +vim.api.nvim_create_autocmd("BufReadPost", { + group = cursor_group, + pattern = "*", + callback = function() + -- Get the row and column of the last cursor position mark + local mark = vim.api.nvim_buf_get_mark(0, '"') + local lcount = vim.api.nvim_buf_line_count(0) + + -- If the mark is valid, jump to it, unless it's a git commit message + if mark[1] > 0 and mark[1] <= lcount and vim.bo.filetype ~= "gitcommit" then + pcall(vim.api.nvim_win_set_cursor, 0, mark) + end + end, +}) + -- Shortcuts vim.cmd([[map :FzfLua combine pickers=buffers,git_files]]) vim.cmd([[map f :FzfLua combine pickers=buffers,files]])