rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

Custom keymaps being overwritten on setup

Open theoribeiro opened this issue 2 years ago • 4 comments

I'm having trouble setting up Rust-tools with LunarVim as it is changing some of my keymaps. For instance, by default LunarVim sets up K (shift + k) to call vim.lsp.buf.hover(). After configuring rust-tools, K is calling man for the token under the cursor. Obviously, this generates errors if I press K on a function name, for example:

image

Is there any way to make sure rust-tools does not configure any keymappings without explicit configuration on my part?

theoribeiro avatar Feb 02 '23 19:02 theoribeiro

I have the same question

jmininger avatar Feb 07 '23 19:02 jmininger

Same here - is there any workaround?

ZarCastic avatar Feb 12 '23 20:02 ZarCastic

Same! Hope to get this addressed.

y1ca1 avatar Mar 12 '23 22:03 y1ca1

I had the same issue. If you are setting up lsp with lspconfig, you might have a function with your lsp related keybindings like so:

local on_attach = function(client, bufnr)
	-- keybind options
	local opts = { noremap = true, silent = true, buffer = bufnr }

	-- set keybinds
	keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references
	keymap.set("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- got to declaration
	keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
	keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
	keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
	keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
	keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show  diagnostics for line
	keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor
	keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer
	keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer
	keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
	keymap.set("n", "<leader>o", "<cmd>Lspsaga outline<CR>", opts) -- see outline on right hand side

	-- typescript specific keymaps (e.g. rename file and update imports)
	if client.name == "tsserver" then
		keymap.set("n", "<leader>rf", ":TypescriptRenameFile<CR>") -- rename file and update imports
		keymap.set("n", "<leader>oi", ":TypescriptOrganizeImports<CR>") -- organize imports (not in youtube nvim video)
		keymap.set("n", "<leader>ru", ":TypescriptRemoveUnused<CR>") -- remove unused variables (not in youtube nvim video)
	end
end

-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()

You can then pass it to the rust-tools setup function:

rust_tools.setup({
	server = {
		capabilities = capabilities,
		on_attach = on_attach,
	},
})

Trzcin avatar Mar 15 '23 17:03 Trzcin