Copilot Chat functionality without having to leave Vim.
Nvim folks will be able to use CopilotChat.nvim for a similar experience.
- Requirements
- Installation
- Setup
- Commands
- Key Mappings
- Features
- Custom Configuration
- Troubleshooting
- Contributing
- Vim 9.0+
- Nerd Fonts (Optional for pretty icons)
- Active GitHub Copilot subscription
Using vim-plug, Vundle, Pathogen, Vim 8+ packages, or any other plugin manager.
vim-plug (Recommended)
Add to your .vimrc:
call plug#begin()
Plug 'DanBradbury/copilot-chat.vim'
call plug#end()
filetype plugin indent onThen run :PlugInstall in Vim.
Vundle
Add to your .vimrc:
call vundle#begin()
Plugin 'DanBradbury/copilot-chat.vim'
call vundle#end()
filetype plugin indent onThen run :PluginInstall in Vim.
Pathogen
Clone the repository:
git clone https://github.com/DanBradbury/copilot-chat.vim.git ~/.vim/bundle/copilot-chat.vimAdd to your .vimrc:
call pathogen#infect()
syntax on
filetype plugin indent onVim 8+ packages
Clone the repository:
git clone https://github.com/DanBradbury/copilot-chat.vim.git ~/.vim/pack/plugins/start/copilot-chat.vimAdd to your .vimrc:
filetype plugin indent on- After installing the plugin, the first time you launch Vim you'll be presented with the device registration page in your default browser
- Follow the steps on the page and paste the Device Code when prompted
- Once completed, press
<Enter>back in Vim to complete the registration process - Start chatting with Copilot (
:CopilotChatOpen,:CopilotChat simple question, etc.) - 🎉 You're ready to go!
| Command | Description |
|---|---|
:CopilotChat <input> |
Launch a new Copilot chat with your input as the initial prompt |
:CopilotChatOpen |
Open a new Copilot chat window (default: vsplit right) |
:CopilotChatFocus |
Focus the currently active chat window |
:CopilotChatReset |
Reset the current chat window |
:CopilotChatClose |
Close the current chat window |
:CopilotChatConfig |
Open config.json for default settings |
: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 if no name provided) |
:CopilotChatList |
List all saved chat histories |
:CopilotChatSetActive [bufnr] |
Set the active chat window (defaults to current buffer) |
:CopilotChatUsage |
Show Copilot usage stats |
| Key | Description |
|---|---|
<Plug>CopilotChatAddSelection |
Copy selected text into active chat buffer |
| Mode | Key | Action |
|---|---|---|
| Normal | <CR> |
Submit current prompt |
| Normal (Models popup) | <CR> or <Space> |
Select the highlighted model |
The plugin intentionally avoids setting global key mappings to prevent conflicts. Here are some suggested mappings for your .vimrc:
" Open a new Copilot Chat window
nnoremap <leader>cc :CopilotChatOpen<CR>
" Focus existing chat window
nnoremap <leader>cf :CopilotChatFocus<CR>
" Add visual selection to chat
vmap <leader>ca <Plug>CopilotChatAddSelection
" Reset chat conversation
nnoremap <leader>cr :CopilotChatReset<CR>Type /tab all in the chat window to automatically expand into a list of all open tabs (excluding the current buffer) with their filenames prefixed by #file:. If no other tabs are found, No other tabs found will be inserted.
Type #file: in the chat window for intelligent file path autocomplete:
- Suggests files from the current Git repository (if in a Git project)
- Falls back to all files in the current working directory
- Excludes directories, only shows files
- Filters based on text typed after
#file:
Example: Typing #file:src/ shows files in the src/ directory.
Use :CopilotChatModels to open a popup menu of available models. Press <Enter> or <Space> to select. New chats will use the selected model.
Visually select code and use <Plug>CopilotChatAddSelection (or your custom mapping) to add it to the active chat window inside a filetype-specific code block.
Save and restore your chat conversations:
Saving:
:CopilotChatSave my-refactoring-session
:CopilotChatSave " Uses timestamp if no name providedLoading:
:CopilotChatLoad my-refactoring-session
:CopilotChatLoad " Shows list of available histories
:CopilotChatList " View all saved chat historiesHistory files are stored in ~/.vim/copilot-chat/history/ as JSON files.
Save and reuse frequently used prompts. In the chat window, start a line with > PROMPT_NAME to expand the template.
- Open config:
:CopilotChatConfig - Add prompts to
config.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:",
"test": "Write unit tests for this code:",
"review": "Review this code for bugs and best practices:"
}
}> explain
function validateUser() {
// code to validate
}
The > explain will be replaced with the full template text before sending to Copilot.
Customize behavior by setting global variables in your .vimrc:
| Variable | Default | Description |
|---|---|---|
g:copilot_chat_window_position |
'right' |
Split direction: 'right', 'left', 'top', 'bottom' |
g:copilot_chat_disable_mappings |
0 |
Set to 1 to disable default chat window mappings |
g:copilot_chat_create_on_add_selection |
1 |
Create new chat when adding selection if none exists |
g:copilot_chat_jump_to_chat_on_add_selection |
1 |
Jump to chat window after adding selection |
g:copilot_reuse_active_chat |
1 |
Reuse active chat window instead of creating new ones |
g:copilot_chat_data_dir |
~/.vim/copilot-chat/ |
Directory for plugin data storage |
g:copilot_chat_open_on_toggle |
1 |
Set to 0 to prevent opening on toggle |
g:copilot_list_chat_buffer |
0 |
Set to 1 to list copilot-chat buffers |
g:copilot_chat_message_history_limit |
20 |
Maximum messages sent to API (lower = faster) |
g:copilot_chat_syntax_debounce_ms |
300 |
Debounce delay for syntax highlighting (ms) |
g:copilot_chat_file_cache_timeout |
5 |
Cache timeout for file completion (seconds) |
Open chats in horizontal split at bottom:
let g:copilot_chat_window_position = 'bottom'Performance tuning for long chat sessions:
" Limit context for faster responses
let g:copilot_chat_message_history_limit = 10
" Reduce CPU usage on slower machines
let g:copilot_chat_syntax_debounce_ms = 500
" Reduce system calls for large projects
let g:copilot_chat_file_cache_timeout = 10Customize selection behavior:
" Don't create new chat when adding selection
let g:copilot_chat_create_on_add_selection = 0
" Stay in current window after adding selection
let g:copilot_chat_jump_to_chat_on_add_selection = 0This error means the logged-in GitHub account does not have an active Copilot subscription. Please:
- Verify your GitHub Copilot subscription at https://github.com/settings/copilot
- Ensure your subscription is active and not expired
- Try logging out and back in to refresh your credentials
- Check if you're authenticated: Restart Vim and check for authentication prompts
- Verify network connectivity
- Try resetting the chat with
:CopilotChatReset
- Ensure you're in a valid directory
- For Git projects, verify the repository is initialized
- Try adjusting
g:copilot_chat_file_cache_timeoutfor better performance
Please see the contribution guide for more information.



