This commit is contained in:
Saeed Afzal
2024-09-05 09:51:17 +01:00
parent 7bd33bd2fb
commit dc2774419d
6 changed files with 70 additions and 54 deletions

View File

@@ -0,0 +1,31 @@
local M = {}
function M.open()
local line = vim.api.nvim_get_current_line()
local cursor_pos = vim.api.nvim_win_get_cursor(0)
local col = cursor_pos[2]
local pattern = "%[%[([^%]]+%.md)%]%]"
local start_pos, end_pos, file = line:find(pattern)
if start_pos and col >= start_pos - 1 and col <= end_pos then
if vim.fn.filereadable(file) == 1 then
vim.cmd('edit ' .. file)
else
print("File not found: " .. file)
end
else
print("No valid Markdown link under cursor.")
end
end
function M.setup()
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.api.nvim_set_keymap("n", "gd", ":lua require('markdown_navigator').open()", {})
end
})
end
return M