summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-24 11:26:59 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-24 17:02:51 +0200
commitc901526977bae4efc478dd9084349c29898fc9ab (patch)
treeb5bfe054306db34c107c568da64795400bbe987a /plugin
parenta0499d3a48b759f909f52076019a0f19b573daf8 (diff)
downloadnvim-config-c901526977bae4efc478dd9084349c29898fc9ab.tar.gz
nvim-config-c901526977bae4efc478dd9084349c29898fc9ab.zip
misc(nvim): note name/heading autocompletion
Diffstat (limited to 'plugin')
-rw-r--r--plugin/50-notes.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/plugin/50-notes.lua b/plugin/50-notes.lua
index 8b64d59..3172a02 100644
--- a/plugin/50-notes.lua
+++ b/plugin/50-notes.lua
@@ -3,7 +3,8 @@
--
-- * Turns the directory in `$NOTES_DIR` into a wiki of markdown notes linked with `[[wiki-links]]`.
-- * Generates ctags for the notes and regenerates them whenever a note is written.
--- * Provides 'omnifunc' wiki-link completion: note names inside `[[`, headings after `#`.
+-- * Provides 'omnifunc' wiki-link completion: note names inside `[[`, headings after `#`;
+-- auto-triggered as soon as `[[` or `#` is typed in a notes buffer.
-- * Provides fzf-lua pickers to find notes by tag/name/section, by file name, or by content.
-- * Provides rename commands that move the note (or rewrite a heading) and update every
-- `[[wiki-link]]` pointing to it across all notes, editing loaded buffers in place and the rest
@@ -480,6 +481,26 @@ vim.api.nvim_create_autocmd("BufWritePost", {
callback = generate_tags,
})
+-- Pop wiki-link completion as soon as `[[` (note name) or `#` (heading) is typed. 'autocomplete'
+-- only triggers on keyword characters, so it would otherwise wait for the first note-name char.
+-- This watches the typed text instead of mapping `[`, so nvim-autopairs keeps its `[` -> `[]` rule;
+-- the omnifunc silently cancels (returns -3) when the cursor is not inside an open `[[`, so the `#`
+-- triggers on plain headings are harmless.
+vim.api.nvim_create_autocmd("TextChangedI", {
+ desc = "Trigger wiki-link completion after `[[` or `#`",
+ group = vim.g.dotfiles.augroup,
+ callback = function()
+ if vim.bo.omnifunc ~= "v:lua.dotfiles_wikilink_source" or vim.fn.pumvisible() == 1 then
+ return
+ end
+ local col = vim.api.nvim_win_get_cursor(0)[2]
+ local before = vim.api.nvim_get_current_line():sub(1, col)
+ if before:sub(-2) == "[[" or before:sub(-1) == "#" then
+ vim.api.nvim_feedkeys(vim.keycode("<C-x><C-o>"), "n", false)
+ end
+ end,
+})
+
vim.api.nvim_create_user_command(
"NotesRename",
rename_note_command,