Copilot.vim を使ってCLIからコミットする際に、コミットメッセージを補完してもらう。
基本的には、Copilot.vimのGetting started
に記載があるとおりに進める。
1. NeovimかVimか
- Install Neovim or the latest patch of Vim (9.0.0185 or newer).
2. Node.jsのインストール
- Install Node.js.
もしインストールしていなければ、Node.jsをインストールする。
3. copilot.vimのインストール
Install github/copilot.vim using vim-plug, packer.nvim, or any other plugin manager. Or to install manually, run one of the following commands:
ご自身の環境に合うインストール方法で。
自分はNeovim, Linux/macOS なので↓
$ git clone https://github.com/github/copilot.vim.git \
~/.config/nvim/pack/github/start/copilot.vim
4. GitHub Copilotと連携する
Neovim/Vimを起動して、:Copilot setup
指示に従って連携していく。
Copilot: Authenticated as GitHub user hogehoge
って表示されたらOK。
IDEとかで既に連携済みなら、↑が表示されると思う。
5. ファイルタイプの有効化
どうやらデフォルトではコミットメッセージやmarkdown等のファイル形式でのサジェストは無効化されているらしいので、設定ファイルで下記を有効化しておく。
ref. Tips for using Github Copilot in Vim
let g:copilot_filetypes = {
\ 'gitcommit': v:true,
\ 'markdown': v:true,
\ 'yaml': v:true
\ }
自分は設定ファイルはLuaで記述しているため、init.luaに↓を追記。
vim.g.copilot_filetypes = { markdown = true, gitcommit = true, yaml = true }
6. コミットする際はdiffも表示する
コミットメッセージテンプレートにdiffが表示されていた方がサジェストの精度が上がった印象。
コミットする際は、-v
オプションを付けてあげた方が良さそう。