Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage: Unclear how to unset lspconfig keybinding #93

Closed
JJGO opened this issue Jan 21, 2023 · 3 comments · Fixed by #85
Closed

usage: Unclear how to unset lspconfig keybinding #93

JJGO opened this issue Jan 21, 2023 · 3 comments · Fixed by #85

Comments

@JJGO
Copy link

JJGO commented Jan 21, 2023

First, thanks for developing and publishing this, it's really great as a starting point for neovim.

I was checking the plugins/example.lua trying to check how to unset premade keybindings by LazyVim. In particular, I want to use the K keymap in normal mode for moving this around with mini.move. I'm doing this by adding the following to my init.lua

require("mini.move").setup({
  mappings = {
    left = "H",
    right = "L",
    down = "J",
    up = "K",
    line_left = "H",
    line_right = "L",
    line_down = "J",
    line_up = "K",
  },
})

However, the on_attach call by lspconfig that LazyVim preconfigures in keymaps.lua takes precendence so K doesn't call the mini.move function.

As a sanity check

:nmap K
n  K           *@<Lua 807: /usr/local/Cellar/neovim/0.8.1/share/nvim/runtime/lua/vim/lsp/buf.lua:41>
                 Hover
n  K           * <Cmd>lua MiniMove.move_line('up')<CR>
                 Move line up

What is the intended way of disabling particular keybindings done vim LazyVim in this way?

@al-ce
Copy link

al-ce commented Jan 21, 2023

Don't know if this is the most efficient way but I copied the entire plugins/lsp/init.lua file in my plugins/ folder (I used plugins/lsp.lua where I put some other lsp related plugin configs) because there were some other things I wanted to change. Relevant changes below:

  {
    "neovim/nvim-lspconfig",
    -- other relevant lazy.nvim settings here, including opts table
    config = function(plugin, opts)
      -- other config stuff here

      -- setup formatting and keymaps
      require("lazyvim.util").on_attach(function(client, buffer)
        require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
        -- require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
        require("config.lsp_keymaps").on_attach(client, buffer)
      end)

    -- Other config stuff here
    })
    end
  }

I comment out the on_attach call for keymaps I think you're referring to, while keeping the format opts. Then I add a call to config/lsp_keymaps.lua (where the optional keymaps.lua/options.lua etc files are in the runtime path) that just has a copy of plugins/lsp/keymaps.lua, and from there I can comment out/edit whatever.

Again, not sure that's the most efficient way, but I like it since I can update to any other changes I want to follow with little hassle, since lazy.nvim makes updates so easy to follow.

@folke
Copy link
Collaborator

folke commented Jan 21, 2023

I'll see for an easier way to override those mapping tomorrow!

@folke folke closed this as completed in 47ba46f Jan 22, 2023
@folke
Copy link
Collaborator

folke commented Jan 22, 2023

I just pushed some change to make it easier to delete/add/change lsp keymaps:

  {
    "neovim/nvim-lspconfig",
    init = function()
      local keys = require("lazyvim.plugins.lsp.keymaps").get()
      -- change a keymap
      keys[#keys + 1] = { "K", "<cmd>echo 'hello'<cr>" }
      -- disable a keymap
      keys[#keys + 1] = { "K", false }
      -- add a keymap
      keys[#keys + 1] = { "H", "<cmd>echo 'hello'<cr>" }
    end,
}

The keymap definition is the same as for the lazy.nvim keys property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants