Skip to content

Instantly share code, notes, and snippets.

@kmckelvin
Created April 19, 2025 14:54
Show Gist options
  • Save kmckelvin/cfd72ea28b194fecfc31f1c224ccbd1d to your computer and use it in GitHub Desktop.
Save kmckelvin/cfd72ea28b194fecfc31f1c224ccbd1d to your computer and use it in GitHub Desktop.
local function edit_file_under_cursor()
vim.cmd('normal! viWo"py')
local grabbed_string = vim.fn.getreg("p")
vim.api.nvim_input("<ESC>")
local file, line_number = string.match(grabbed_string, "(.-):([0-9]+)")
if line_number == nil then
file = grabbed_string
end
if vim.loop.fs_stat(vim.fn.getcwd() .. "/" .. file) ~= nil then
vim.cmd("wincmd p")
vim.cmd("e " .. file)
if line_number ~= nil then
vim.cmd("normal " .. line_number .. "gg")
end
end
end
vim.keymap.set("n", "<leader>gf", edit_file_under_cursor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment