Skip to content

Instantly share code, notes, and snippets.

@kohane27
Created December 16, 2022 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohane27/0c6088c8f146c9c8312061cd05b05dcc to your computer and use it in GitHub Desktop.
Save kohane27/0c6088c8f146c9c8312061cd05b05dcc to your computer and use it in GitHub Desktop.
jump.lua
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