From 4a83cc866d4b1bef620cd69d4bdbfa642320e2b0 Mon Sep 17 00:00:00 2001 From: Ind1eMonk3y Date: Mon, 26 Apr 2021 23:44:05 +0200 Subject: [PATCH] Enhance cursor offset saving/restoring --- lua/harpoon/mark.lua | 10 ++++++---- lua/harpoon/ui.lua | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index a5097e6..089162d 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -62,10 +62,11 @@ local function get_buf_name(id) end local function create_mark(filename) + local cursor_pos = vim.fn.getcurpos() return { filename = filename, - row = 0, - col = 0, + row = cursor_pos[2], + col = cursor_pos[3], } end @@ -179,8 +180,9 @@ M.store_offset = function() return end - harpoon.get_mark_config().marks[idx].row = - vim.fn.line("."); + local cursor_pos = vim.fn.getcurpos() + harpoon.get_mark_config().marks[idx].row = cursor_pos[2] + harpoon.get_mark_config().marks[idx].col = cursor_pos[3] end) if not ok then diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index c87e163..720c5fa 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -106,7 +106,7 @@ M.nav_file = function(id) vim.api.nvim_set_current_buf(buf_id) if set_row and mark.row then - vim.cmd(string.format(":%d", mark.row)) + vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col)) end end