Created
December 16, 2022 15:13
-
-
Save kohane27/0c6088c8f146c9c8312061cd05b05dcc to your computer and use it in GitHub Desktop.
jump.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local CONTEXT = 8 | |
-- change line col text | |
-- 4 18 9 change one | |
-- 3 28 21 change two | |
-- 2 39 23 change three | |
-- 1 54 13 another change | |
local function get_text(changelist, current) | |
local width = 0 | |
local lines = {} | |
local current_line | |
for i = current - 3, current + 10 do | |
local j = changelist[i] | |
if j then | |
local bufname = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":~:.") | |
local line = string.format("%s:%d:%d", bufname, j.lnum, j.col) | |
if #line > width then | |
width = #line | |
end | |
lines[#lines + 1] = { | |
{ bufname }, | |
{ string.format(":%d:%d", j.lnum, j.col), "Directory" }, | |
} | |
if current == i then | |
current_line = #lines | |
end | |
if #lines > CONTEXT then | |
break | |
end | |
end | |
end | |
return lines, current_line, width | |
end | |
local function show_jumps(forward) | |
local changelist, last_jump_pos = unpack(vim.fn.getchangelist()) | |
local changelistResult = vim.inspect(changelist) | |
vim.notify(changelistResult) | |
local current = last_jump_pos + 1 + (forward and 1 or -1) | |
if current == 0 then | |
current = 1 | |
end | |
if current > #changelist then | |
current = #changelist | |
end | |
local lines, current_line, width = get_text(changelist, current) | |
end | |
vim.keymap.set("n", "<C-o>", function() | |
show_jumps() | |
return "<C-o>" | |
end, { expr = true, desc = "show jumps" }) | |
vim.keymap.set("n", "<C-i>", function() | |
show_jumps(true) | |
return "<C-i>" | |
end, { expr = true, desc = "show jumps" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment