Note
A new command, CopilotChatInPlace
has been introduced. It functions like the ChatGPT plugin. Please run ":UpdateRemotePlugins" command and restart Neovim before starting a chat with Copilot. To stay updated on our roadmap, please join our Discord community.
Ensure you have the following installed:
- Python 3.10 or later
It will prompt you with instructions on your first start. If you already have Copilot.vim
or Copilot.lua
, it will work automatically.
pip install python-dotenv requests pynvim==0.5.0 prompt-toolkit
pip install tiktoken
(optional for displaying prompt token counts)- Put it in your lazy setup
return {
{
"CopilotC-Nvim/CopilotChat.nvim",
opts = {
show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes
debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log
disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response.
-- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks.
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
event = "VeryLazy",
keys = {
{ "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{
"<leader>ccv",
":CopilotChatVisual",
mode = "x",
desc = "CopilotChat - Open in vertical split",
},
{
"<leader>ccx",
":CopilotChatInPlace<cr>",
mode = "x",
desc = "CopilotChat - Run in-place code",
},
},
},
}
- Run command
:UpdateRemotePlugins
, then inspect the file~/.local/share/nvim/rplugin.vim
for additional details. You will notice that the commands have been registered.
For example:
" python3 plugins
call remote#host#RegisterPlugin('python3', '/Users/huynhdung/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py', [
\ {'sync': v:false, 'name': 'CopilotChat', 'type': 'command', 'opts': {'nargs': '1'}},
\ {'sync': v:false, 'name': 'CopilotChatVisual', 'type': 'command', 'opts': {'nargs': '1', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatInPlace', 'type': 'command', 'opts': {'nargs': '*', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatAutocmd', 'type': 'command', 'opts': {'nargs': '*'}},
\ {'sync': v:false, 'name': 'CopilotChatMapping', 'type': 'command', 'opts': {'nargs': '*'}},
\ ])
- Restart
neovim
- Put the files in the right place
$ git clone https://github.com/CopilotC-Nvim/CopilotChat.nvim
$ cd CopilotChat.nvim
$ cp -r --backup=nil rplugin ~/.config/nvim/
- Install dependencies
$ pip install -r requirements.txt
- Open up Neovim and run
:UpdateRemotePlugins
- Restart Neovim
You have the ability to tailor this plugin to your specific needs using the configuration options outlined below:
{
debug = false, -- Enable or disable debug mode
show_help = 'yes', -- Show help text for CopilotChatInPlace
prompts = { -- Set dynamic prompts for CopilotChat commands
Explain = 'Explain how it works.',
Tests = 'Briefly explain how the selected code works, then generate unit tests.',
}
}
You have the capability to expand the prompts to create more versatile commands:
return {
"CopilotC-Nvim/CopilotChat.nvim",
opts = {
debug = true,
show_help = "yes",
prompts = {
Explain = "Explain how it works.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
event = "VeryLazy",
keys = {
{ "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{ "<leader>ccr", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
{ "<leader>ccR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
}
}
For further reference, you can view @jellydn's configuration.
- Copy some code into the unnamed register using the
y
command. - Run the command
:CopilotChat
followed by your question. For example,:CopilotChat What does this code do?
- Copy some code into the unnamed register using the
y
command. - Run the command
:CopilotChatExplain
.
- Copy some code into the unnamed register using the
y
command. - Run the command
:CopilotChatTests
.
- Select some code using visual mode.
- Run the command
:CopilotChatVisual
with your question.
- Select some code using visual mode.
- Run the command
:CopilotChatInPlace
and type your prompt. For example,What does this code do?
- Press
Enter
to send your question to Github Copilot. - Press
q
to quit. There is help text at the bottom of the screen. You can also press?
to toggle the help text.
If you encounter any issues, you can run the command :messages
to inspect the log. You can also run the command :CopilotChatDebugInfo
to inspect the debug information.
A special thanks to @ecosse3 for the configuration of which-key.
{
"CopilotC-Nvim/CopilotChat.nvim",
event = "VeryLazy",
opts = {
prompts = {
Explain = "Explain how it works.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
config = function()
local present, wk = pcall(require, "which-key")
if not present then
return
end
wk.register({
c = {
c = {
name = "Copilot Chat",
}
}
}, {
mode = "n",
prefix = "<leader>",
silent = true,
noremap = true,
nowait = false,
})
end,
keys = {
{ "<leader>ccc", ":CopilotChat ", desc = "CopilotChat - Prompt" },
{ "<leader>cce", ":CopilotChatExplain ", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{ "<leader>ccr", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
{ "<leader>ccR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
}
},
Follow the example below to create a simple input for CopilotChat.
-- Create input for CopilotChat
{
"<leader>cci",
function()
local input = vim.fn.input("Ask Copilot: ")
if input ~= "" then
vim.cmd("CopilotChat " .. input)
end
end,
desc = "CopilotChat - Ask input",
},
{
"CopilotC-Nvim/CopilotChat.nvim",
keys =
function()
local keybinds={
--add your custom keybinds here
}
-- change prompt and keybinds as per your need
local my_prompts = {
{prompt = "In Neovim.",desc = "Neovim",key = "n"},
{prompt = "Help with this",desc = "Help",key = "h"},
{prompt = "Simplify and imporve readablilty",desc = "Simplify",key = "s"},
{prompt = "Optimize the code to improve perfomance and readablilty.",desc = "Optimize",key = "o"},
{prompt = "Find possible errors and fix them for me",desc = "Fix",key = "f"},
{prompt = "Explain in detail",desc = "Explain",key = "e"},
{prompt = "Write a shell scirpt",desc = "Shell",key = "S"},
}
-- you can change <leader>cc to your desired keybind prefix
for _,v in pairs(my_prompts) do
table.insert(keybinds,{ "<leader>cc"..v.key, ":CopilotChatVisual "..v.prompt.."<cr>", mode = "x", desc = "CopilotChat - "..v.desc })
table.insert(keybinds,{ "<leader>cc"..v.key, "<cmd>CopilotChat "..v.prompt.."<cr>", desc = "CopilotChat - "..v.desc })
end
return keybinds
end,
},
- Use vector encodings to automatically select code
- Treesitter integration for function definitions
- General QOL improvements
For development, you can use the provided Makefile command to install the pre-commit tool:
make install-pre-commit
This will install the pre-commit tool and the pre-commit hooks.
Thanks goes to these wonderful people (emoji key):
gptlang 💻 📖 |
Dung Duc Huynh (Kaka) 💻 📖 |
Ahmed Haracic 💻 |
Trí Thiện Nguyễn 💻 |
He Zhizhou 💻 |
Guruprakash Rajakkannu 💻 |
kristofka 💻 |
PostCyberPunk 📖 |
This project follows the all-contributors specification. Contributions of any kind are welcome!