epwalsh / obsidian.nvim

Obsidian 🤝 Neovim
Apache License 2.0
4.17k stars 188 forks source link

A setting in the config to make ObsidianLink default to opening the picker when a note to link to does not exist #551

Open DRKolev-code opened 6 months ago

DRKolev-code commented 6 months ago

🚀 The feature, motivation and pitch

Pretty much the title. What i do now is:

 { "<leader>l", ObsidianLinkWithCheck, mode = "v", ft = "markdown" },
 { "<leader>l", function() vim.cmd("normal! viw") ObsidianLinkWithCheck() end, mode = "n", ft = "markdown" },

 local function ObsidianLinkWithCheck()
  local current_line = vim.api.nvim_get_current_line()

  vim.cmd("ObsidianLink")

  local check_line = vim.schedule_wrap(function()
    local new_line = vim.api.nvim_get_current_line()
    if new_line == current_line then
      vim.cmd("ObsidianLink .md")
    end
  end)
  vim.defer_fn(check_line, 1)
end

Alternatives

No response

Additional context

No response

epwalsh commented 6 months ago

Hey @DRKolev-code, sure, happy to accept a PR with this. The best way to add this would be to update the logic here: https://github.com/epwalsh/obsidian.nvim/blob/16e98b45b6755222fe74a6b778c958d26bf61edd/lua/obsidian/client.lua#L683 Instead of returning early here, you could call picker:find_notes().

DRKolev-code commented 6 months ago

Will try to do one these days. :)