You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local function refactor_with_backlink()
-- Save the original note's name
local origin_note = vim.fn.expand("%:t:r") -- current file name without extension
-- Call Obsidian's Extract Note command
vim.cmd("ObsidianExtractNote")
-- Delay to ensure ObsidianExtractNote completes before continuing
vim.defer_fn(function()
-- Switch to the new note (should be the most recent entry in the buffer list)
local new_note = vim.fn.expand("%:t:r") -- update this to get the latest buffer
-- Edit the new note and add the backlink to the origin note
vim.cmd("edit " .. new_note) -- Opens the new note
vim.fn.append(0, "[[" .. origin_note .. "]]") -- Insert backlink at the top
end, 300) -- Increased delay to ensure `ObsidianExtractNote` finishes
end
-- Map function to a keybind (visual mode)
vim.api.nvim_set_keymap("v", "rf", ":lua refactor_with_backlink()", { noremap = true, silent = true })
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
tried with chatgpt but keep receiving errors
-- Map function to a keybind (visual mode)
vim.api.nvim_set_keymap("v", "rf", ":lua refactor_with_backlink()", { noremap = true, silent = true })
Beta Was this translation helpful? Give feedback.
All reactions