Alexander Schaaf

Enabling Copilot in NeoVim/NvChad

Not understanding much of NeoVim and how to configure it, let alone NvChad, it was surprisingly tricky to get GitHub Copilot to work within it. Installing the plugin was the easy part, but by default it uses the Tab key to accept suggestions, which is already mapped in NvChad.

To get it to work, I had to disable the default mapping and add my own.

First thing is to add the github/copilot.vim plugin to the plugin list in ~/.config/nvim/lua/plugins.lua:

return {
    -- ...
  {
    "github/copilot.vim",
    lazy = false,
    config = function() -- Mapping tab is already used in NvChad
      vim.g.copilot_no_tab_map = true; -- Disable tab mapping
      vim.g.copilot_assume_mapped = true; -- Assume that the mapping is already done
    end
  }
}

Then, in ~/.config/nvim/lua/mappings.lua, add the following:

map('i', '<C-l>', function ()
  vim.fn.feedkeys(vim.fn['copilot#Accept'](), '')
end, { desc = 'Copilot Accept', noremap = true, silent = true })

This will map ctrl + l to accept the suggestion.