Copilot Chat functionality without having to leave Vim.
Nvim folks will be able to use CopilotChat.nvim for a similar experience.
Using Vundle, Pathogen vim-plug, Vim 8+ packages, or any other plugin manager.
Add into .vimrc
configuration.
call vundle#begin()
Plugin 'DanBradbury/copilot-chat.vim'
call vundle#end()
filetype plugin indent on
Clone repository.
git clone https://github.com/DanBradbury/copilot-chat.vim.git ~/.vim/bundle
Add into .vimrc
configuration.
call pathogen#infect()
syntax on
filetype plugin indent on
Add into .vimrc
configuration.
call plug#begin()
Plug 'DanBradbury/copilot-chat.vim'
call plug#end()
filetype plugin indent on
Clone repository.
git clone https://github.com/DanBradbury/copilot-chat.vim.git ~/.vim/pack/plugins/start
Add into .vimrc
configuration.
filetype plugin indent on
- Run
:CopilotChatOpen
to open a chat window. You will be prompted to setup your device on first use. - Write your prompt under the line separator and press
<Enter>
in normal mode. - You should see a
Waiting for response..
in the buffer to indicate work is being done in the background. - πππ
Command | Description |
---|---|
:CopilotChat <input> |
Launches a new Copilot chat with your input as the initial prompt |
:CopilotChatOpen |
Opens a new Copilot chat window (default vsplit right) |
:CopilotChatFocus |
Focuses the currently active chat window |
:CopilotChatReset |
Resets the current chat window |
:CopilotChatConfig |
Open config.json for default settings when opening a new CopilotChat window |
:CopilotChatModels |
View available models / select active model |
:CopilotChatSave <name>? |
Save chat history (uses timestamp if no name provided) |
:CopilotChatLoad <name>? |
Load chat history (shows list of saved histories if no name provided) |
:CopilotChatList |
List all saved chat histories |
:CopilotChatSetActive <bufnr>? |
Sets the active chat window to the buffer number provided (default is the current buffer) |
Key | Description |
---|---|
<Plug>CopilotChatAddSelection |
Copies selected text into active char buffer |
Location | Insert | Normal | Visual | Action |
---|---|---|---|---|
Chat window | - | <CR> |
- | Submit current prompt |
Models selection popup | - | <CR> |
<Space> |
- |
The plugin avoids adding any default vim key mappings to prevent conflict with other plugins and the users' own mappings.
However, to easily work with the Copilot Chat plugin, the user might want to setup his own vim key mappings. See example configuration below:
" Open a new Cpilot Chat window
nnoremap <leader>cc :CopilotChatOpen<CR>
" Add visual selection to copilot window
vmap <leader>a <Plug>CopilotChatAddSelection
The plugin includes autocomplete macros, specifically designed to enhance productivity when working with file references.
- Typing
/tab all
in the chat window will automatically expand into a list of all open tabs (excluding the current buffer) with their filenames prefixed by#file:
. - The filenames are displayed in their relative path format, making it easier to reference files in your project.
- If no other tabs are found, the message
No other tabs found
will be inserted instead.
- When typing
#file:
in the chat window, the plugin provides an autocomplete menu for file paths. - The autocomplete intelligently suggests files based on:
- Files tracked in the current Git repository (if inside a Git project).
- All files in the current working directory (if not in a Git project).
- The suggestions exclude directories and only include files that match the text typed after
#file:
. - Example:
- Typing
#file:src/
will show a list of files in thesrc/
directory. - Selecting a file from the menu will insert its full path.
- Typing
:CopilotChatModels
brings up a popup menu for of all the available models for you to choose from. Press <Enter>
or <Space>
to select the highlighted model. New chats will use the selected model.
By default, this is configured to <Leader>a
when in visual mode.
Save and restore your chat conversations with Copilot:
- Use
:CopilotChatSave <name>
to save the current chat history - If no name is provided, a timestamp will be used automatically
- History files are stored in
~/.vim/copilot-chat/history/
as JSON files
- Use
:CopilotChatLoad <name>
to load a previously saved chat - If no name is provided, a list of available chat histories will be shown
- You can also view all saved histories with
:CopilotChatList
Copilot Chat supports custom prompt templates that can be quickly accessed during chat sessions. Templates allow you to save frequently used prompts and invoke them with a simple syntax.
- In the chat window, start a line with
> PROMPT_NAME
- The
PROMPT_NAME
will be automatically replaced with the template content before sending to Copilot - Example:
> explain
would expand to the full explanation template
- Open the config with
:CopilotChatConfig
- Add prompts to the
prompts
object inconfig.json
:
{
"model": "gpt-4",
"prompts": {
"explain": "Explain how this code works in detail:",
"refactor": "Suggest improvements and refactoring for this code:",
"docs": "Generate documentation for this code:"
}
}
> explain
function validateUser() {
// code to validate
}
This will send the full template text + your code to Copilot.
Please see the contribution guide for more information.