-- Default paths for custom links local project_base_path = vim.fn.expand("~/5ika/brain/project") local area_base_path = vim.fn.expand("~/5ika/brain/area") -- Template paths local project_template_path = vim.fn.expand("~/5ika/brain/templates/project.md") local area_template_path = vim.fn.expand("~/5ika/brain/templates/area.md") -- Configurable prefixes for custom links local link_prefixes = { project = "+", area = "@", } -- Function to create a file from a template local function create_file_from_template(full_path, template_path) local template_content = vim.fn.readfile(template_path) vim.fn.writefile(template_content, full_path) print("Created new file from template: " .. full_path) end -- Function to follow custom links function follow_custom_link() local word = vim.fn.expand("") local full_path, template_path if string.match(word, "^" .. link_prefixes.project .. "%w+$") then local project_name = string.gsub(word, "^" .. link_prefixes.project, "") full_path = project_base_path .. "/" .. project_name .. ".md" template_path = project_template_path elseif string.match(word, "^" .. link_prefixes.area .. "%w+$") then local area_name = string.gsub(word, "^" .. link_prefixes.area, "") full_path = area_base_path .. "/" .. area_name .. ".md" template_path = area_template_path else print("Not a custom link") return end if vim.fn.filereadable(full_path) == 1 or vim.fn.isdirectory(full_path) == 1 then vim.cmd("edit " .. full_path) else create_file_from_template(full_path, template_path) vim.cmd("edit " .. full_path) end end -- Key mapping to follow custom links vim.api.nvim_set_keymap("n", "fl", ":lua follow_custom_link()", { noremap = true, silent = true })