luaneovimnvim.cmp

Tab keymap collision between nvim-cmp and copilot.vim in AstroNvim


I'm using AstroNvim, and just installed copilot.vim. It's working fine, except that I want to use the Tab key to accept a copilot suggestion. However, the Tab key is mapped to 'Next Completion' according to the AstroNvim docs. How do I disable this behavior so that the Tab key is only used for accepting Copilot suggestions?

I have tried adding the following code in my lua/plugins/cmp.lua file:

return {
  "hrsh7th/nvim-cmp",
  opts = function(_, opts)
    local cmp = require("cmp")
    opts.mapping["<Tab>"] = nil
  end
}

It hasn't had any effect however.


Solution

  • I used these snippets:

    In cmp.lua:

    return {
      "hrsh7th/nvim-cmp",
      opts = function(_, opts)
        local cmp = require("cmp")
        opts.mapping["<Tab>"] = nil
      end
    }
    

    In astrocore.lua:

    return {
      "AstroNvim/astrocore",
      options = {...},
      mappings = {
        i = {
          ["<CR>"] = "copilot#Accept('\\<CR>')"
        }
      }
    }