jinzhongjia / LspUI.nvim

A modern and useful UI plugin that wraps lsp operations.
MIT License
158 stars 4 forks source link

How to bind commands? #7

Closed mariusju closed 1 year ago

mariusju commented 1 year ago

Hi! first of all - thanks for creating this plugin. I arrived at it exactly for the same problem - every time I need to setup my nvim environment, lsp saga is broken for different reasons, I just cant afford wasting time on that over and over. Looking forward to try LspUI.

I am not an advanced nvim+lua user, I coudln't figure out how to bind commands from your docs. Could you give me an example, lets say how to bind code_actions command to <leader>ca?

Thank you!

jinzhongjia commented 1 year ago

in config, when we enable "command_enable", just like default config, LspUI will auto register command like LspUI hover LspUI code_action etc

you can just add this in lspconfig on_attach(This will only trigger bind keypresses when the lsp is mounted on the buffer)

just like this:

local opt = { noremap = true, silent = true }
vim.api.nvim_buf_set_keymap("n", "<leader>ca", "<cmd>LspUI code_action<CR>", opt)
jinzhongjia commented 1 year ago

here is my keybinding file, https://github.com/jinzhongjia/neovim-config/blob/lsp/lua/plugin-config/mason/lsp/keybind.lua

mariusju commented 1 year ago

oh, i didn't realize that I had to enable commands when using just the defaults. Works like a charm, thanks again ❤️