which-key.nvim
which-key.nvim copied to clipboard
[Help with implementation]
Hello,
I am trying to implement a set of custom keymappings to use with buffers that have neovimLSP running on them. My setup script for the LSP calls this file to setup the key mapping for the buffers I open. However these key mappings are not being registered
Could someone help me understand whats wrong in my code?
local M = {}
local whichkey = require "which-key"
local keymap = vim.api.nvim_set_keymap
local buf_keymap = vim.api.nvim_buf_set_keymap
local function keymappings(client, bufnr)
local opts = { noremap = true, silent = true }
-- Key mappings
buf_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
keymap("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
keymap("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
keymap("n", "[e", "<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<CR>", opts)
keymap("n", "]e", "<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<CR>", opts)
-- Whichkey
local keymap_t = {
t = {
name = "Code",
r = { "<cmd>lua vim.lsp.buf.rename()<CR>", "Rename" },
a = { "<cmd>lua vim.lsp.buf.code_action()<CR>", "Code Action" },
d = { "<cmd>lua vim.diagnostic.open_float()<CR>", "Line Diagnostics" },
i = { "<cmd>LspInfo<CR>", "Lsp Info" },
},
}
if client.resolved_capabilities.document_formatting then
keymap_t.l.f = { "<cmd>lua vim.lsp.buf.formatting()<CR>", "Format Document" }
end
whichkey.register(keymap_t, { buffer = bufnr, prefix = "<leader>" })
end
function M.setup(client, bufnr)
keymappings(client, bufnr)
end
return M
- Are you calling
require("<this_script>").setup{client=<client>, bufnr=<buffer>}
anywhere? In someBufEnter
autocmd perhaps scoping to buffers? - You don't seem to be passing
bufnr
to the which-key -wrappedvim.*.buf.*
commands, not an expert here but I think those are scoped to specific buffers (so the LSP knows the language I assume)
Look here for examples: https://github.com/neovim/nvim-lspconfig#suggested-configuration
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.