From 7a051952fcd28aa81b4a1c0997e7e12190587bff Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2024 14:53:48 +0200 Subject: [PATCH] nvim: Update which-key mapping functions Use new which-key mapping `.add()` functions after `.register()` has been deprecated with which-key 3.0.0. --- nvim/.config/nvim/after/ftplugin/markdown.lua | 8 +++++--- nvim/.config/nvim/after/ftplugin/quarto.lua | 16 --------------- nvim/.config/nvim/lua/core/mappings.lua | 12 ++++++----- nvim/.config/nvim/lua/plugins/config/lsp.lua | 8 ++++---- nvim/.config/nvim/lua/plugins/core.lua | 2 +- .../nvim/lua/plugins/data_analysis.lua | 6 +++++- nvim/.config/nvim/lua/plugins/git.lua | 20 +++++++++++-------- nvim/.config/nvim/lua/plugins/ide.lua | 2 +- nvim/.config/nvim/lua/plugins/prose.lua | 9 +++++---- nvim/.config/nvim/lua/plugins/telescope.lua | 12 +++++------ 10 files changed, 46 insertions(+), 49 deletions(-) diff --git a/nvim/.config/nvim/after/ftplugin/markdown.lua b/nvim/.config/nvim/after/ftplugin/markdown.lua index 84ad5c0..d7f2888 100644 --- a/nvim/.config/nvim/after/ftplugin/markdown.lua +++ b/nvim/.config/nvim/after/ftplugin/markdown.lua @@ -1,8 +1,10 @@ local map = vim.keymap.set if require("core.util").is_available("which-key") then - require("which-key").register({ ["c"] = { name = "+codecells" } }) - require("which-key").register({ ["e"] = { name = "+criticmarkup" } }) + require("which-key").add({ + { "c", group = "codecells" }, + { "e", group = "criticmarkup" }, + }) end if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then @@ -23,7 +25,7 @@ map("n", "co", "o```python```k", { desc = "Insert quar map("n", "cO", "O```python```k", { desc = "Insert quarto cell above" }) if require("core.util").is_available("which-key") then - require("which-key").register({ ["p"] = { name = "+prose" } }) + require("which-key").add({ "p", group = "prose" }) end -- show nice md preview in browser (auto-syncs scrolling) if require("core.util").is_available("peek") then diff --git a/nvim/.config/nvim/after/ftplugin/quarto.lua b/nvim/.config/nvim/after/ftplugin/quarto.lua index b6a8d7f..565bf04 100644 --- a/nvim/.config/nvim/after/ftplugin/quarto.lua +++ b/nvim/.config/nvim/after/ftplugin/quarto.lua @@ -56,19 +56,3 @@ if vim.g.quarto_auto_init_molten_session then end, }) end - --- -- -- TODO find better way to enable lsp key mappings for quarto buffers --- -- local prefix = require("which-key").register --- -- prefix({ ["l"] = { name = "+lsp" } }) --- -- map("n", "li", "LspInfo", { buffer = bufnr, desc = "Lsp Info" }) --- -- map("n", "ld", "lua vim.diagnostic.open_float()", { buffer = bufnr, desc = "Line diagnostics" }) --- -- map("n", "la", "lua vim.lsp.buf.code_action()", { buffer = bufnr, desc = "Codeactions" }) --- -- map("n", "ln", "lua vim.lsp.buf.rename()", { buffer = bufnr, desc = "Rename element" }) --- -- map("n", "lr", "lua vim.lsp.buf.references()", { buffer = bufnr, desc = "References" }) --- -- --- -- map("n", "gD", "lua vim.lsp.buf.declaration()", { buffer = bufnr, desc = "Declaration" }) --- -- map("n", "gs", "lua vim.lsp.buf.signature_help()", { buffer = bufnr, desc = "Signature help" }) --- -- map("n", "gI", "lua vim.lsp.buf.implementation()", { buffer = bufnr, desc = "Implementation" }) --- -- map("n", "gt", "lua vim.lsp.buf.type_definition()", { buffer = bufnr, desc = "Type definition" }) - --- vim.g["python3_host_prog"] = vim.fn.expand(require("core.util").get_python_venv()) diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index 5f61ba8..4384247 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -2,11 +2,13 @@ local map = vim.keymap.set local is_available = require("core.util").is_available if is_available("which-key") then - local prefix = require("which-key").register - prefix({ ["v"] = { name = "+vim" } }) - prefix({ ["s"] = { name = "+show" } }) - prefix({ ["s"] = { name = "+set" } }) - prefix({ ["Z"] = { name = "+spelling" } }) + local prefix = require("which-key").add + prefix({ + { "v", group = "vim" }, + { "s", group = "show" }, + { "s", group = "set" }, + { "Z", group = "spelling" }, + }) end -- The general ideas behind these mappings: diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index cfecf0a..94dee61 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -64,7 +64,7 @@ local function on_attach(_, bufnr) ) if require("core.util").is_available("which-key") then - require("which-key").register({ ["l"] = { name = "+language" } }) + require("which-key").add({ "l", group = "language" }) end map( "n", @@ -160,9 +160,9 @@ lspconfig.marksman.setup({ on_attach = function(client, bufnr) -- TODO: for some reason this stays true even after rootdir switch? if client.config.in_zk_notebook then - vim.defer_fn(function() - vim.lsp.buf_detach_client(bufnr, client.id) - end, 1000) + vim.defer_fn(function() + vim.lsp.buf_detach_client(bufnr, client.id) + end, 1000) end on_attach(client, bufnr) end, diff --git a/nvim/.config/nvim/lua/plugins/core.lua b/nvim/.config/nvim/lua/plugins/core.lua index 878f302..d267be6 100644 --- a/nvim/.config/nvim/lua/plugins/core.lua +++ b/nvim/.config/nvim/lua/plugins/core.lua @@ -86,8 +86,8 @@ return { { "micarmst/vim-spellsync", event = "VeryLazy" }, { "folke/which-key.nvim", - config = true, event = "CursorHold", + opts = { icons = { mappings = false } }, }, -- collection of plugins { diff --git a/nvim/.config/nvim/lua/plugins/data_analysis.lua b/nvim/.config/nvim/lua/plugins/data_analysis.lua index 3fbc520..5088b87 100644 --- a/nvim/.config/nvim/lua/plugins/data_analysis.lua +++ b/nvim/.config/nvim/lua/plugins/data_analysis.lua @@ -46,6 +46,10 @@ return { map("n", "[c", "?^```n}:nohl", { desc = "Codecell last" }) map("n", "co", "o```{python}```k", { desc = "Insert quarto cell below" }) map("n", "cO", "O```{python}```k", { desc = "Insert quarto cell above" }) + + if require("core.util").is_available("which-key") then + require("which-key").add({ "c", group = "codecells" }) + end end, ft = { "quarto" }, }, @@ -114,7 +118,7 @@ return { callback = function() local map = vim.keymap.set if require("core.util").is_available("which-key") then - require("which-key").register({ ["c"] = { name = "+codecells" } }) + require("which-key").add({ "c", group = "codecells" }) end -- Operate jupyter notebooks from within vim map( diff --git a/nvim/.config/nvim/lua/plugins/git.lua b/nvim/.config/nvim/lua/plugins/git.lua index cc24131..e227f6a 100644 --- a/nvim/.config/nvim/lua/plugins/git.lua +++ b/nvim/.config/nvim/lua/plugins/git.lua @@ -1,18 +1,22 @@ return { { "akinsho/git-conflict.nvim", - event = "VeryLazy", + event = { "InsertEnter", "CursorHold" }, config = function() require("git-conflict").setup({ default_mappings = false, disable_diagnostics = true, }) - vim.keymap.set("n", "ho", "(git-conflict-ours)", { desc = "Conflict use ours" }) - vim.keymap.set("n", "hO", "(git-conflict-theirs)", { desc = "Conflict use theirs" }) - vim.keymap.set("n", "hm", "(git-conflict-both)", { desc = "Conflict use both" }) - vim.keymap.set("n", "hM", "(git-conflict-none)", { desc = "Conflict use none" }) - vim.keymap.set("n", "[H", "(git-conflict-prev-conflict)", { desc = "Prev git conflict" }) - vim.keymap.set("n", "]H", "(git-conflict-next-conflict)", { desc = "Next git conflict" }) + if require("core.util").is_available("which-key") then + require("which-key").add({ "h", group = "git" }) + end + local map = vim.keymap.set + map("n", "ho", "(git-conflict-ours)", { desc = "Conflict use ours" }) + map("n", "hO", "(git-conflict-theirs)", { desc = "Conflict use theirs" }) + map("n", "hm", "(git-conflict-both)", { desc = "Conflict use both" }) + map("n", "hM", "(git-conflict-none)", { desc = "Conflict use none" }) + map("n", "[H", "(git-conflict-prev-conflict)", { desc = "Prev git conflict" }) + map("n", "]H", "(git-conflict-next-conflict)", { desc = "Next git conflict" }) end, lazy = false, -- TODO needs to be force refreshed in lazy loaded mode unfortunately }, @@ -56,7 +60,7 @@ return { -- Actions if require("core.util").is_available("which-key") then - require("which-key").register({ ["h"] = { name = "+git" } }) + require("which-key").add({ "h", group = "git" }) end map({ "n", "v" }, "hs", ":Gitsigns stage_hunk", { desc = "stage hunk" }) map({ "n", "v" }, "hr", ":Gitsigns reset_hunk", { desc = "reset hunk" }) diff --git a/nvim/.config/nvim/lua/plugins/ide.lua b/nvim/.config/nvim/lua/plugins/ide.lua index 0634d04..40bb8f1 100644 --- a/nvim/.config/nvim/lua/plugins/ide.lua +++ b/nvim/.config/nvim/lua/plugins/ide.lua @@ -264,7 +264,7 @@ return { }, }) if require("core.util").is_available("which-key") then - require("which-key").register({ ["t"] = { name = "+test" } }) + require("which-key").add({ "t", group = "test" }) end end, ft = { "python" }, diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index 502fc34..8be45c7 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -94,10 +94,11 @@ local prose_plugs = { "mickael-menu/zk-nvim", config = function() if require("core.util").is_available("which-key") then - local prefix = require("which-key").register - prefix({ ["n"] = { name = "+notes" } }) - prefix({ ["n"] = { name = "+note" } }) - prefix({ ["n"] = { name = "+note", mode = "v" } }) + require("which-key").add({ + { "n", group = "notes" }, + { "n", group = "note" }, + { "n", group = "note", mode = "v" }, + }) require("zk.commands").add("ZkOrphans", function(opts) opts = vim.tbl_extend("force", { orphan = true }, opts or {}) diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua index a32bf82..67d3e4e 100644 --- a/nvim/.config/nvim/lua/plugins/telescope.lua +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -10,7 +10,7 @@ return { cmd = "Telescope", config = function() if require("core.util").is_available("which-key") then - require("which-key").register({ ["f"] = { name = "+find" } }) + require("which-key").add({ "f", group = "find" }) end -- Setup up telescope fuzzy finding settings -- @@ -37,10 +37,10 @@ return { selection_caret = "󰳟 ", color_devicons = true, mappings = { - -- FIXME Find way to only invoke this *IF* trouble plugin is found - i = { [""] = require("trouble.sources.telescope").open }, - n = { [""] = require("trouble.sources.telescope").open }, - } + -- FIXME Find way to only invoke this *IF* trouble plugin is found + i = { [""] = require("trouble.sources.telescope").open }, + n = { [""] = require("trouble.sources.telescope").open }, + }, }, pickers = { buffers = { theme = "ivy" }, @@ -82,7 +82,7 @@ return { function() require("telescope.builtin").colorscheme(require("telescope.themes").get_ivy()) end, - desc = "colorschemes" , + desc = "colorschemes", }, {