From 8f826f1f6fe7656291a7c7b36ff943a417bdcde4 Mon Sep 17 00:00:00 2001 From: juan Date: Mon, 8 Aug 2022 16:40:00 +0800 Subject: [PATCH] Update zk mappings --- lua/mappings.lua | 5 +++-- lua/plugins/zk.lua | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index 953c6b5..db9a763 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -32,8 +32,9 @@ map('i', '?', '?u', {noremap = true}) -- gitsigns map('', 'gs', ':Gitsigns toggle_signs', {silent = true}) -- lsp stuff -vim.api.nvim_buf_set_keymap(0, 'n', 'K', 'lua vim.lsp.buf.hover()', - {noremap = true}) +map('n', 'gd', 'lua vim.lsp.buf.definition()', + {silent = false, noremap = true}) +map('n', 'K', 'lua vim.lsp.buf.hover()', {noremap = true}) map('', 'K', 'lua vim.diagnostic.open_float()', {noremap = true}) map('', 'qf', diff --git a/lua/plugins/zk.lua b/lua/plugins/zk.lua index dbb8457..da24d84 100644 --- a/lua/plugins/zk.lua +++ b/lua/plugins/zk.lua @@ -17,3 +17,37 @@ require("zk").setup({ auto_attach = {enabled = true, filetypes = {"markdown"}} } }) + +-- mappings +-- Add the key mappings only for Markdown files in a zk notebook. +if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then + local map = vim.api.nvim_set_keymap + local opts = {noremap = true, silent = false} + + -- Open the link under the caret. + map("n", "", "lua vim.lsp.buf.definition()", opts) + + -- Create a new note after asking for its title. + -- This overrides the global `zn` mapping to create the note in the same directory as the current buffer. + map("n", "zn", + "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", + opts) + -- Create a new note in the same directory as the current buffer, using the current selection for title. + map("v", "znt", + ":'<,'>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') }", + opts) + -- Create a new note in the same directory as the current buffer, using the current selection for note content and asking for its title. + map("v", "znc", + ":'<,'>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", + opts) + + -- Open notes linking to the current buffer. + map("n", "zb", "ZkBacklinks", opts) + -- Alternative for backlinks using pure LSP and showing the source context. + -- map('n', 'zb', 'lua vim.lsp.buf.references()', opts) + -- Open notes linked by the current buffer. + map("n", "zl", "ZkLinks", opts) + + -- Open the code actions for a visual selection. + map("v", "za", ":'<,'>lua vim.lsp.buf.range_code_action()", opts) +end