diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-24 10:43:43 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-24 17:02:51 +0200 |
| commit | a0499d3a48b759f909f52076019a0f19b573daf8 (patch) | |
| tree | deae3efe735ada30c093e56de816598aa186a88b /plugin/50-notes.lua | |
| parent | bb02d0dc5f80c76e81da91855d49264d5c854b53 (diff) | |
| download | nvim-config-a0499d3a48b759f909f52076019a0f19b573daf8.tar.gz nvim-config-a0499d3a48b759f909f52076019a0f19b573daf8.zip | |
misc(nvim): add shortcut to navigate URL and wikilinks
Diffstat (limited to 'plugin/50-notes.lua')
| -rw-r--r-- | plugin/50-notes.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/plugin/50-notes.lua b/plugin/50-notes.lua index f128447..8b64d59 100644 --- a/plugin/50-notes.lua +++ b/plugin/50-notes.lua @@ -21,6 +21,7 @@ -- `<Leader>nn`: fuzzy-find notes -- `<Leader>nf`: fuzzy-find notes by file name -- `<Leader>ng`: fuzzy-find notes by content +-- `<Tab>` / `<S-Tab>` (in notes buffers): go to next/previous URL or wiki-link -- if vim.env.NOTES_DIR == nil then @@ -398,17 +399,36 @@ local function rename_section_command(opts) end ---------------------------------------------------------------------------------------------------- +-- Navigation -------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- + +-- Moves the cursor to the start of the next (or previous, when `backward`) URL or `[[wiki-link]]`, +-- wrapping around the buffer. "URL" means a `scheme://…` target, matching the follow engine in +-- 50-goto.lua. +local function goto_url(backward) + local pattern = [[\v(\a[0-9A-Za-z+.-]*://\S+|\[\[.{-}\]\])]] + vim.fn.search(pattern, backward and "bw" or "w") +end + +---------------------------------------------------------------------------------------------------- -- Buffer init & pickers --------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -- Initializes a notes buffer -- * Include generated notes tags in 'tags' option -- * Enable wikilink completion +-- * Map <Tab>/<S-Tab> to jump between URLs/wiki-links local function init_notes_buffer() if not vim.tbl_contains(vim.opt_local.tags:get(), tagfile) then vim.opt_local.tags:append(tagfile) end vim.bo.omnifunc = "v:lua.dotfiles_wikilink_source" + vim.keymap.set("n", "<Tab>", function() + goto_url(false) + end, { buffer = true, desc = "Go to next URL/wiki-link" }) + vim.keymap.set("n", "<S-Tab>", function() + goto_url(true) + end, { buffer = true, desc = "Go to previous URL/wiki-link" }) end local function find_notes_by_tag() |
