/CopilotChat.nvim

Chat with GitHub Copilot in Neovim

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Copilot Chat for Neovim

All Contributors

Authentication

It will prompt you with instructions on your first start. If you already have Copilot.vim or Copilot.lua, it will work automatically.

Installation

Lazy.nvim

  1. pip install python-dotenv requests pynvim==0.5.0 prompt-toolkit
  2. Put it in your lazy setup
return {
  {
    "jellydn/CopilotChat.nvim",
    opts = {
      mode = "split", -- newbuffer or split  , default: newbuffer
    },
    build = function()
      vim.defer_fn(function()
        vim.cmd("UpdateRemotePlugins")
        vim.notify("CopilotChat - Updated remote plugins. Please restart Neovim.")
      end, 3000)
    end,
    event = "VeryLazy",
    keys = {
      { "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
      { "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
    },
  },
}
  1. Run :UpdateRemotePlugins
  2. Restart neovim

Manual

  1. Put the files in the right place
$ git clone https://github.com/gptlang/CopilotChat.nvim
$ cd CopilotChat.nvim
$ cp -r --backup=nil rplugin ~/.config/nvim/
  1. Install dependencies
$ pip install -r requirements.txt
  1. Open up Neovim and run :UpdateRemotePlugins
  2. Restart Neovim

Usage

Configuration

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
  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 {
    "jellydn/CopilotChat.nvim",
    opts = {
      mode = "split",
      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.defer_fn(function()
        vim.cmd("UpdateRemotePlugins")
        vim.notify("CopilotChat - Updated remote plugins. Please restart Neovim.")
      end, 3000)
    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 my configuration.

Chat with Github Copilot

  1. Copy some code into the unnamed register using the y command.
  2. Run the command :CopilotChat followed by your question. For example, :CopilotChat What does this code do?

Chat Demo

Code Explanation

  1. Copy some code into the unnamed register using the y command.
  2. Run the command :CopilotChatExplain.

Explain Code Demo

Generate Tests

  1. Copy some code into the unnamed register using the y command.
  2. Run the command :CopilotChatTests.

Generate tests

Roadmap

  • Translation to pure Lua
  • Tokenizer
  • Use vector encodings to automatically select code
  • Sub commands - See issue #5

Contributors ✨

Thanks goes to these wonderful people (emoji key):

gptlang
gptlang

💻 📖
Dung Duc Huynh (Kaka)
Dung Duc Huynh (Kaka)

💻 📖
Ahmed Haracic
Ahmed Haracic

💻
Trí Thiện Nguyễn
Trí Thiện Nguyễn

💻

This project follows the all-contributors specification. Contributions of any kind welcome!