summaryrefslogtreecommitdiff
path: root/after
diff options
context:
space:
mode:
authorMarcelo <setanta@gmail.com>2025-04-03 23:49:35 -0300
committerMarcelo <setanta@gmail.com>2025-04-04 00:10:31 -0300
commitd4677b4cb0f367c871eed674c50eb9555cc8adeb (patch)
treea4e5682d91a45d7535c5975c66b5bc89e4cb3fd7 /after
parent622b5cc8da61ace34dee4a453326dbd33e7b58b8 (diff)
Improve Zettelkasten notes keybind situation.
Diffstat (limited to 'after')
-rw-r--r--after/ftplugin/markdown.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua
new file mode 100644
index 0000000..8fbe798
--- /dev/null
+++ b/after/ftplugin/markdown.lua
@@ -0,0 +1,25 @@
+if require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then
+ vim.keymap.set("n", "<CR>", vim.lsp.buf.definition,
+ { buffer = true, noremap = true, silent = false, desc = "Open the link under the caret." })
+
+ -- Create a new note in the same directory as the current buffer, using the current selection for title.
+ vim.keymap.set("v", "<Leader>zn", ":'<,'>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') }<CR>",
+ { buffer = true, noremap = true, silent = false, desc = "Create a new note using the current selection for title." })
+
+ -- Create a new note in the same directory as the current buffer,
+ -- using the current selection for note content and asking for its title.
+ vim.keymap.set("v", "<Leader>zN",
+ ":'<,'>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<CR>",
+ { buffer = true, noremap = true, silent = false, desc = "Create a new note using the current selection for contents." })
+
+ vim.keymap.set("n", "<Leader>zb", "<CMD>ZkBacklinks<CR>",
+ { buffer = true, noremap = true, silent = false, desc = "Open notes linking to the current buffer." })
+
+ -- Alternative for backlinks using pure LSP and showing the source context.
+ -- The results will appear in the quickfix list.
+ vim.keymap.set("n", "<Leader>zB", vim.lsp.buf.references,
+ { buffer = true, noremap = true, silent = false, desc = "Open notes linking to the current buffer with LSP." })
+
+ vim.keymap.set("n", "<Leader>zl", "<CMD>ZkLinks<CR>",
+ { buffer = true, noremap = true, silent = false, desc = "Open notes linked by the current buffer." })
+end