Created
April 19, 2025 14:54
-
-
Save kmckelvin/cfd72ea28b194fecfc31f1c224ccbd1d to your computer and use it in GitHub Desktop.
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 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