I use Neovim with Lazy.nvim and I want to use GitHub Copilot only for very specific cases. For me, is better to have it unabled than enabled by default, and just activate it when I need to use it (kind of asking something to chatgpt I guess), so I try to accomplish this by lazy loading it in the plugin configuration, like this:
return {
"github/copilot.vim",
-- disable copilot by default
lazy = true,
keys = { "<leader>ce" },
config = function()
vim.keymap.set("i", "<C-j>", 'copilot#Accept("\<CR>")', {
expr = true,
replace_keycodes = false,
})
vim.keymap.set("n", "<leader>cd", ":Copilot disable <CR>", {})
vim.keymap.set("n", "<leader>ce", ":Copilot enable <CR>", {})
end,
}
It works, it is not loaded until I press ce, but I do not receive autocompletion after that, I can acces :Copilot <command>
, but this does not autocomplete my text/code, any idea why?
UPDATE: I added a line in my configuration and that kind of work, but it freezes my screen for like 2 seconds and then I can use as normal, does anyone know why do I need to run :Copilot setup
to use it but before lazy loading it I did’t need to do it?
return {
"github/copilot.vim",
-- disable copilot by default
lazy = true,
keys = { "<leader>ce" },
config = function()
vim.cmd("Copilot setup") -- Line I added
vim.keymap.set("i", "<C-j>", 'copilot#Accept("\<CR>")', {
expr = true,
replace_keycodes = false,
})
vim.keymap.set("n", "<leader>cd", ":Copilot disable <CR>", {})
vim.keymap.set("n", "<leader>ce", ":Copilot enable <CR>", {})
end,
}
By the way, here is my complete config file.