nvim: Update which-key mapping functions

Use new which-key mapping `.add()` functions after `.register()` has
been deprecated with which-key 3.0.0.
This commit is contained in:
Marty Oehme 2024-07-24 14:53:48 +02:00
parent d45d220b52
commit 7a051952fc
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
10 changed files with 46 additions and 49 deletions

View file

@ -1,8 +1,10 @@
local map = vim.keymap.set local map = vim.keymap.set
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>c"] = { name = "+codecells" } }) require("which-key").add({
require("which-key").register({ ["<localleader>e"] = { name = "+criticmarkup" } }) { "<localleader>c", group = "codecells" },
{ "<localleader>e", group = "criticmarkup" },
})
end end
if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then 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", "<localleader>co", "o```python<cr><cr>```<esc>k", { desc = "Insert quar
map("n", "<localleader>cO", "O```python<cr><cr>```<esc>k", { desc = "Insert quarto cell above" }) map("n", "<localleader>cO", "O```python<cr><cr>```<esc>k", { desc = "Insert quarto cell above" })
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>p"] = { name = "+prose" } }) require("which-key").add({ "<localleader>p", group = "prose" })
end end
-- show nice md preview in browser (auto-syncs scrolling) -- show nice md preview in browser (auto-syncs scrolling)
if require("core.util").is_available("peek") then if require("core.util").is_available("peek") then

View file

@ -56,19 +56,3 @@ if vim.g.quarto_auto_init_molten_session then
end, end,
}) })
end end
-- -- -- TODO find better way to enable lsp key mappings for quarto buffers
-- -- local prefix = require("which-key").register
-- -- prefix({ ["<localleader>l"] = { name = "+lsp" } })
-- -- map("n", "<localleader>li", "<cmd>LspInfo<cr>", { buffer = bufnr, desc = "Lsp Info" })
-- -- map("n", "<localleader>ld", "<cmd>lua vim.diagnostic.open_float()<cr>", { buffer = bufnr, desc = "Line diagnostics" })
-- -- map("n", "<localleader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", { buffer = bufnr, desc = "Codeactions" })
-- -- map("n", "<localleader>ln", "<cmd>lua vim.lsp.buf.rename()<cr>", { buffer = bufnr, desc = "Rename element" })
-- -- map("n", "<localleader>lr", "<cmd>lua vim.lsp.buf.references()<cr>", { buffer = bufnr, desc = "References" })
-- --
-- -- map("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", { buffer = bufnr, desc = "Declaration" })
-- -- map("n", "gs", "<cmd>lua vim.lsp.buf.signature_help()<cr>", { buffer = bufnr, desc = "Signature help" })
-- -- map("n", "gI", "<cmd>lua vim.lsp.buf.implementation()<cr>", { buffer = bufnr, desc = "Implementation" })
-- -- map("n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<cr>", { buffer = bufnr, desc = "Type definition" })
-- vim.g["python3_host_prog"] = vim.fn.expand(require("core.util").get_python_venv())

View file

@ -2,11 +2,13 @@ local map = vim.keymap.set
local is_available = require("core.util").is_available local is_available = require("core.util").is_available
if is_available("which-key") then if is_available("which-key") then
local prefix = require("which-key").register local prefix = require("which-key").add
prefix({ ["<leader>v"] = { name = "+vim" } }) prefix({
prefix({ ["<leader>s"] = { name = "+show" } }) { "<leader>v", group = "vim" },
prefix({ ["<localleader>s"] = { name = "+set" } }) { "<leader>s", group = "show" },
prefix({ ["<localleader>Z"] = { name = "+spelling" } }) { "<localleader>s", group = "set" },
{ "<localleader>Z", group = "spelling" },
})
end end
-- The general ideas behind these mappings: -- The general ideas behind these mappings:

View file

@ -64,7 +64,7 @@ local function on_attach(_, bufnr)
) )
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>l"] = { name = "+language" } }) require("which-key").add({ "<localleader>l", group = "language" })
end end
map( map(
"n", "n",
@ -160,9 +160,9 @@ lspconfig.marksman.setup({
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
-- TODO: for some reason this stays true even after rootdir switch? -- TODO: for some reason this stays true even after rootdir switch?
if client.config.in_zk_notebook then if client.config.in_zk_notebook then
vim.defer_fn(function() vim.defer_fn(function()
vim.lsp.buf_detach_client(bufnr, client.id) vim.lsp.buf_detach_client(bufnr, client.id)
end, 1000) end, 1000)
end end
on_attach(client, bufnr) on_attach(client, bufnr)
end, end,

View file

@ -86,8 +86,8 @@ return {
{ "micarmst/vim-spellsync", event = "VeryLazy" }, { "micarmst/vim-spellsync", event = "VeryLazy" },
{ {
"folke/which-key.nvim", "folke/which-key.nvim",
config = true,
event = "CursorHold", event = "CursorHold",
opts = { icons = { mappings = false } },
}, },
-- collection of plugins -- collection of plugins
{ {

View file

@ -46,6 +46,10 @@ return {
map("n", "[c", "?^```<cr>n}:nohl<cr>", { desc = "Codecell last" }) map("n", "[c", "?^```<cr>n}:nohl<cr>", { desc = "Codecell last" })
map("n", "<localleader>co", "o```{python}<cr><cr>```<esc>k", { desc = "Insert quarto cell below" }) map("n", "<localleader>co", "o```{python}<cr><cr>```<esc>k", { desc = "Insert quarto cell below" })
map("n", "<localleader>cO", "O```{python}<cr><cr>```<esc>k", { desc = "Insert quarto cell above" }) map("n", "<localleader>cO", "O```{python}<cr><cr>```<esc>k", { desc = "Insert quarto cell above" })
if require("core.util").is_available("which-key") then
require("which-key").add({ "<localleader>c", group = "codecells" })
end
end, end,
ft = { "quarto" }, ft = { "quarto" },
}, },
@ -114,7 +118,7 @@ return {
callback = function() callback = function()
local map = vim.keymap.set local map = vim.keymap.set
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>c"] = { name = "+codecells" } }) require("which-key").add({ "<localleader>c", group = "codecells" })
end end
-- Operate jupyter notebooks from within vim -- Operate jupyter notebooks from within vim
map( map(

View file

@ -1,18 +1,22 @@
return { return {
{ {
"akinsho/git-conflict.nvim", "akinsho/git-conflict.nvim",
event = "VeryLazy", event = { "InsertEnter", "CursorHold" },
config = function() config = function()
require("git-conflict").setup({ require("git-conflict").setup({
default_mappings = false, default_mappings = false,
disable_diagnostics = true, disable_diagnostics = true,
}) })
vim.keymap.set("n", "<localleader>ho", "<Plug>(git-conflict-ours)", { desc = "Conflict use ours" }) if require("core.util").is_available("which-key") then
vim.keymap.set("n", "<localleader>hO", "<Plug>(git-conflict-theirs)", { desc = "Conflict use theirs" }) require("which-key").add({ "<localleader>h", group = "git" })
vim.keymap.set("n", "<localleader>hm", "<Plug>(git-conflict-both)", { desc = "Conflict use both" }) end
vim.keymap.set("n", "<localleader>hM", "<Plug>(git-conflict-none)", { desc = "Conflict use none" }) local map = vim.keymap.set
vim.keymap.set("n", "[H", "<Plug>(git-conflict-prev-conflict)", { desc = "Prev git conflict" }) map("n", "<localleader>ho", "<Plug>(git-conflict-ours)", { desc = "Conflict use ours" })
vim.keymap.set("n", "]H", "<Plug>(git-conflict-next-conflict)", { desc = "Next git conflict" }) map("n", "<localleader>hO", "<Plug>(git-conflict-theirs)", { desc = "Conflict use theirs" })
map("n", "<localleader>hm", "<Plug>(git-conflict-both)", { desc = "Conflict use both" })
map("n", "<localleader>hM", "<Plug>(git-conflict-none)", { desc = "Conflict use none" })
map("n", "[H", "<Plug>(git-conflict-prev-conflict)", { desc = "Prev git conflict" })
map("n", "]H", "<Plug>(git-conflict-next-conflict)", { desc = "Next git conflict" })
end, end,
lazy = false, -- TODO needs to be force refreshed in lazy loaded mode unfortunately lazy = false, -- TODO needs to be force refreshed in lazy loaded mode unfortunately
}, },
@ -56,7 +60,7 @@ return {
-- Actions -- Actions
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>h"] = { name = "+git" } }) require("which-key").add({ "<localleader>h", group = "git" })
end end
map({ "n", "v" }, "<localleader>hs", ":Gitsigns stage_hunk<CR>", { desc = "stage hunk" }) map({ "n", "v" }, "<localleader>hs", ":Gitsigns stage_hunk<CR>", { desc = "stage hunk" })
map({ "n", "v" }, "<localleader>hr", ":Gitsigns reset_hunk<CR>", { desc = "reset hunk" }) map({ "n", "v" }, "<localleader>hr", ":Gitsigns reset_hunk<CR>", { desc = "reset hunk" })

View file

@ -264,7 +264,7 @@ return {
}, },
}) })
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>t"] = { name = "+test" } }) require("which-key").add({ "<localleader>t", group = "test" })
end end
end, end,
ft = { "python" }, ft = { "python" },

View file

@ -94,10 +94,11 @@ local prose_plugs = {
"mickael-menu/zk-nvim", "mickael-menu/zk-nvim",
config = function() config = function()
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
local prefix = require("which-key").register require("which-key").add({
prefix({ ["<leader>n"] = { name = "+notes" } }) { "<leader>n", group = "notes" },
prefix({ ["<localleader>n"] = { name = "+note" } }) { "<localleader>n", group = "note" },
prefix({ ["<localleader>n"] = { name = "+note", mode = "v" } }) { "<localleader>n", group = "note", mode = "v" },
})
require("zk.commands").add("ZkOrphans", function(opts) require("zk.commands").add("ZkOrphans", function(opts)
opts = vim.tbl_extend("force", { orphan = true }, opts or {}) opts = vim.tbl_extend("force", { orphan = true }, opts or {})

View file

@ -10,7 +10,7 @@ return {
cmd = "Telescope", cmd = "Telescope",
config = function() config = function()
if require("core.util").is_available("which-key") then if require("core.util").is_available("which-key") then
require("which-key").register({ ["<leader>f"] = { name = "+find" } }) require("which-key").add({ "<leader>f", group = "find" })
end end
-- Setup up telescope fuzzy finding settings -- Setup up telescope fuzzy finding settings
-- --
@ -37,10 +37,10 @@ return {
selection_caret = "󰳟 ", selection_caret = "󰳟 ",
color_devicons = true, color_devicons = true,
mappings = { mappings = {
-- FIXME Find way to only invoke this *IF* trouble plugin is found -- FIXME Find way to only invoke this *IF* trouble plugin is found
i = { ["<c-t>"] = require("trouble.sources.telescope").open }, i = { ["<c-t>"] = require("trouble.sources.telescope").open },
n = { ["<c-t>"] = require("trouble.sources.telescope").open }, n = { ["<c-t>"] = require("trouble.sources.telescope").open },
} },
}, },
pickers = { pickers = {
buffers = { theme = "ivy" }, buffers = { theme = "ivy" },
@ -82,7 +82,7 @@ return {
function() function()
require("telescope.builtin").colorscheme(require("telescope.themes").get_ivy()) require("telescope.builtin").colorscheme(require("telescope.themes").get_ivy())
end, end,
desc = "colorschemes" , desc = "colorschemes",
}, },
{ {