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
if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>c"] = { name = "+codecells" } })
require("which-key").register({ ["<localleader>e"] = { name = "+criticmarkup" } })
require("which-key").add({
{ "<localleader>c", group = "codecells" },
{ "<localleader>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", "<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" })
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
-- show nice md preview in browser (auto-syncs scrolling)
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
-- -- -- 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
if is_available("which-key") then
local prefix = require("which-key").register
prefix({ ["<leader>v"] = { name = "+vim" } })
prefix({ ["<leader>s"] = { name = "+show" } })
prefix({ ["<localleader>s"] = { name = "+set" } })
prefix({ ["<localleader>Z"] = { name = "+spelling" } })
local prefix = require("which-key").add
prefix({
{ "<leader>v", group = "vim" },
{ "<leader>s", group = "show" },
{ "<localleader>s", group = "set" },
{ "<localleader>Z", group = "spelling" },
})
end
-- 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
require("which-key").register({ ["<localleader>l"] = { name = "+language" } })
require("which-key").add({ "<localleader>l", group = "language" })
end
map(
"n",

View file

@ -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
{

View file

@ -46,6 +46,10 @@ return {
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 above" })
if require("core.util").is_available("which-key") then
require("which-key").add({ "<localleader>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({ ["<localleader>c"] = { name = "+codecells" } })
require("which-key").add({ "<localleader>c", group = "codecells" })
end
-- Operate jupyter notebooks from within vim
map(

View file

@ -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", "<localleader>ho", "<Plug>(git-conflict-ours)", { desc = "Conflict use ours" })
vim.keymap.set("n", "<localleader>hO", "<Plug>(git-conflict-theirs)", { desc = "Conflict use theirs" })
vim.keymap.set("n", "<localleader>hm", "<Plug>(git-conflict-both)", { desc = "Conflict use both" })
vim.keymap.set("n", "<localleader>hM", "<Plug>(git-conflict-none)", { desc = "Conflict use none" })
vim.keymap.set("n", "[H", "<Plug>(git-conflict-prev-conflict)", { desc = "Prev git conflict" })
vim.keymap.set("n", "]H", "<Plug>(git-conflict-next-conflict)", { desc = "Next git conflict" })
if require("core.util").is_available("which-key") then
require("which-key").add({ "<localleader>h", group = "git" })
end
local map = vim.keymap.set
map("n", "<localleader>ho", "<Plug>(git-conflict-ours)", { desc = "Conflict use ours" })
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,
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({ ["<localleader>h"] = { name = "+git" } })
require("which-key").add({ "<localleader>h", group = "git" })
end
map({ "n", "v" }, "<localleader>hs", ":Gitsigns stage_hunk<CR>", { desc = "stage 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
require("which-key").register({ ["<localleader>t"] = { name = "+test" } })
require("which-key").add({ "<localleader>t", group = "test" })
end
end,
ft = { "python" },

View file

@ -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({ ["<leader>n"] = { name = "+notes" } })
prefix({ ["<localleader>n"] = { name = "+note" } })
prefix({ ["<localleader>n"] = { name = "+note", mode = "v" } })
require("which-key").add({
{ "<leader>n", group = "notes" },
{ "<localleader>n", group = "note" },
{ "<localleader>n", group = "note", mode = "v" },
})
require("zk.commands").add("ZkOrphans", function(opts)
opts = vim.tbl_extend("force", { orphan = true }, opts or {})

View file

@ -10,7 +10,7 @@ return {
cmd = "Telescope",
config = function()
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
-- Setup up telescope fuzzy finding settings
--
@ -40,7 +40,7 @@ return {
-- FIXME Find way to only invoke this *IF* trouble plugin is found
i = { ["<c-t>"] = require("trouble.sources.telescope").open },
n = { ["<c-t>"] = require("trouble.sources.telescope").open },
}
},
},
pickers = {
buffers = { theme = "ivy" },