Skip to content

DanBradbury/copilot-chat.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Copilot Chat for Vim

Vint Test

Copilot Chat functionality without having to leave Vim.

Nvim folks will be able to use CopilotChat.nvim for a similar experience.

copilotChat

Requirements

Installation

Using Vundle, Pathogen vim-plug, Vim 8+ packages, or any other plugin manager.

vundle

Add into .vimrc configuration.

call vundle#begin()
Plugin 'DanBradbury/copilot-chat.vim'
call vundle#end()

filetype plugin indent on

Pathogen

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

vim-plug

Add into .vimrc configuration.

call plug#begin()
Plug 'DanBradbury/copilot-chat.vim'
call plug#end()

filetype plugin indent on

Vim 8+ packages

Clone repository.

git clone https://github.com/DanBradbury/copilot-chat.vim.git ~/.vim/pack/plugins/start

Add into .vimrc configuration.

filetype plugin indent on

Setup

  1. Run :CopilotChatOpen to open a chat window. You will be prompted to setup your device on first use.
  2. Write your prompt under the line separator and press <Enter> in normal mode.
  3. You should see a Waiting for response.. in the buffer to indicate work is being done in the background.
  4. πŸŽ‰πŸŽ‰πŸŽ‰

Commands

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)

Plugin Keys

Key Description
<Plug>CopilotChatAddSelection Copies selected text into active char buffer

Default Key Mappings

Location Insert Normal Visual Action
Chat window - <CR> - Submit current prompt
Models selection popup - <CR> <Space> -

User Key mappings

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

Features

Autocomplete Macros

The plugin includes autocomplete macros, specifically designed to enhance productivity when working with file references.

/tab all Macro

macros

  • 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.

#file: Macro

filemacro

  • 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 the src/ directory.
    • Selecting a file from the menu will insert its full path.

Model Selection

: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.

Add Selection to Chat

By default, this is configured to <Leader>a when in visual mode.

  • Adds the selection to the active chat window inside of a &filetype named codeblock

Chat History

Save and restore your chat conversations with Copilot:

Saving Chat History

  • 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

Loading Chat History

  • 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

Prompt Templates

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.

Using Prompts

  • 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

Managing Prompts

  1. Open the config with :CopilotChatConfig
  2. Add prompts to the prompts object in 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:"
  }
}

Example Usage

> explain

function validateUser() {
  // code to validate
}

This will send the full template text + your code to Copilot.

Contributing

Please see the contribution guide for more information.

About

Copilot Chat for Vim

Topics

Resources

License

Stars

Watchers

Forks

Languages