AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring GitHub Copilot in Neovim Without Breaking nvim-cmp Tab Completion

Rob Barshad · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Pressing <Tab> in Neovim while typing code should feel like muscle memory. When you introduce GitHub Copilot alongside nvim-cmp, that muscle memory shatters. You press <Tab> hoping to select the next item in your LSP autocomplete menu or jump to a snippet tabstop, but GitHub Copilot swallows the keystroke to insert a three-line hallucinated function. Or worse: nvim-cmp hijacks <Tab> completely, rendering Copilot’s ghost text impossible to accept.

At 365Finds, we see developers waste hours writing tangled Lua wrapper functions to negotiate between these two plugins. The root cause is simple: two distinct completion paradigms—deterministic token matching (nvim-cmp) and predictive multiline text generation (GitHub Copilot)—are competing for the exact same key.

You do not need an over-engineered dispatcher. Here is how to cleanly configure both plugins, why key decoupling is our explicit recommendation, and how to set up the alternatives if your workflow demands a unified menu.


The Core Problem: A Collision of Two Completion Paradigms

To understand the fix, recognize what each plugin expects when you press <Tab> in Insert mode:

  1. nvim-cmp expects <Tab> to cycle forward through popup menu entries (cmp.select_next_item()), expand or advance snippet nodes (such as LuaSnip), or fall back to standard buffer indentation.
  2. GitHub Copilot (either the Vimscript copilot.vim or the Lua-native copilot.lua) defaults <Tab> to accepting its inline virtual ghost text.

When both hooks attach to <Tab>, Neovim executes whichever mapping was registered last or triggers silent mapping collisions. Even if you construct a dynamic conditional function, race conditions occur when GitHub Copilot’s asynchronous network response arrives a split-second after nvim-cmp renders its popup.


365Finds Recommended Solution: Decouple Keymaps (<M-l> for Copilot)

365Finds strongly advocates for complete key separation. We prefer keeping <Tab> strictly reserved for nvim-cmp and snippet navigation, while binding GitHub Copilot acceptance to <M-l> (Alt+L) or <C-j>.

Why? Multi-line code generation and single-word LSP completions require different cognitive decisions. Forcing them onto one key leads to accidental accepts when you only wanted a variable name. Alt+L sits comfortably on the home row, avoids any conflict with terminal signals, and completely eliminates race conditions.

Scenario A: Using zbirenbaum/copilot.lua (Modern Lua Setup)

If you use zbirenbaum/copilot.lua, configure its inline suggestion module directly in your plugin setup:

-- lua/plugins/copilot.lua
require("copilot").setup({
  suggestion = {
    enabled = true,
    auto_trigger = true,
    debounce = 75,
    keymap = {
      accept = "<M-l>",          -- Alt + l to accept full ghost text
      accept_word = "<M-w>",     -- Alt + w to accept next word
      accept_line = "<M-]>",     -- Alt + ] to accept current line
      next = "<M-n>",            -- Alt + n to cycle to next suggestion
      prev = "<M-p>",            -- Alt + p to cycle to previous suggestion
      dismiss = "<C-]>",         -- Ctrl + ] to discard suggestion
    },
  },
  panel = { enabled = false },
})

Then, in your nvim-cmp configuration, keep your standard super-tab behavior for snippets and menu navigation without worrying about Copilot interference:

-- lua/plugins/cmp.lua
local cmp = require("cmp")
local luasnip = require("luasnip")

cmp.setup({
  snippet = {
    expand = function(args)
      luasnip.lsp_expand(args.body)
    end,
  },
  mapping = cmp.mapping.preset.insert({
    ["<Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      elseif luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      else
        fallback()
      end
    end, { "i", "s" }),

    ["<S-Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_previous_item()
      elseif luasnip.jumpable(-1) then
        luasnip.jump(-1)
      else
        fallback()
      end
    end, { "i", "s" }),

    ["<CR>"] = cmp.mapping.confirm({ select = false }),
  }),
  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "luasnip" },
    { name = "path" },
    { name = "buffer" },
  }),
})

Scenario B: Using Official github/copilot.vim (Vimscript Core)

If you are running GitHub’s official copilot.vim plugin in Neovim, setting up copilot.lua config tables will do nothing. You must tell the global Vimscript runtime to release <Tab> before mapping a new key:

-- Disable copilot.vim default Tab mapping
vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true

-- Remap Copilot accept to <M-l> in Insert mode
vim.keymap.set("i", "<M-l>", 'copilot#Accept("<CR>")', {
  expr = true,
  replace_keycodes = false,
  silent = true,
})

Setting vim.g.copilot_assume_mapped = true prevents the plugin from issuing startup warnings about <Tab> being hijacked by nvim-cmp.


Alternative 1: The Contextual Super-Tab (Single Key Dispatch)

Some developers refuse to press anything other than <Tab>. If you insist on a unified key, you must make nvim-cmp aware of Copilot’s suggestion state.

Here is how you wire a hierarchical fallback into nvim-cmp using copilot.lua:

local cmp = require("cmp")
local copilot_suggestion = require("copilot.suggestion")
local luasnip = require("luasnip")

cmp.setup({
  mapping = {
    ["<Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      elseif copilot_suggestion.is_visible() then
        copilot_suggestion.accept()
      elseif luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      else
        fallback()
      end
    end, { "i", "s" }),
  },
})

Notice the strict order: cmp.visible() must be evaluated first. If an LSP popup is active, pressing <Tab> should move through the list; otherwise, accepting ghost text while a popup is open corrupts the current line.


Alternative 2: Feeding Copilot Into nvim-cmp Menu via copilot-cmp

Another approach is discarding inline ghost text altogether and turning GitHub Copilot into a regular source item inside the nvim-cmp popup menu.

Using zbirenbaum/copilot-cmp:

-- 1. In copilot.lua, turn off suggestions and panel
require("copilot").setup({
  suggestion = { enabled = false },
  panel = { enabled = false },
})

-- 2. Initialize copilot-cmp
require("copilot_cmp").setup()

-- 3. Add copilot to nvim-cmp sources
local cmp = require("cmp")
cmp.setup({
  sources = {
    { name = "copilot", group_index = 2 },
    { name = "nvim_lsp", group_index = 2 },
    { name = "luasnip", group_index = 2 },
    { name = "buffer", group_index = 3 },
  },
})

While this eliminates key collisions cleanly, 365Finds finds this tradeoff questionable. GitHub Copilot excels at predicting multi-line blocks of boilerplate and testing logic. Squishing multi-line AI suggestions into a tiny 40-character popup dropdown cuts off context and reduces its practical utility.


Diagnostic Checklist

When your Tab key misbehaves after editing your configuration:

  1. Check existing buffer mappings: run :verbose imap <Tab> in Neovim. The output reveals exactly which plugin or runtime file registered the last mapping.
  2. Verify GitHub Copilot authentication: run :Copilot status (or :Copilot auth for copilot.lua). An unauthenticated plugin silently swallows inputs or yields no suggestions.
  3. Confirm debounce timing: with copilot.lua, keep debounce = 75 ms. Setting debounce to zero creates UI stuttering when typing rapidly alongside LSP diagnostics.

References