vim で github copilot を使う
はじめに
最近ようやく github copilot を契約し,私は最強になってしまったわけです.
ただ,私は vscode 以外に vim も使うので,vim で動かす方法・詰まったところを備忘録として残しておきます.メモです!
動作環境
- Mac
- Vim version 9.1.754
インストール方法
copilot.vim によると下記の手順で OK.
- Install vim
- Install Node.js
- Install github/copilot.vim using vim-plug, lazy.nvim, or any other plugin manager. Or to install manually, run one of the following commands:
- Vim, Linux/macOS:
git clone --depth=1 https://github.com/github/copilot.vim.git \ ~/.vim/pack/github/start/copilot.vim
- Vim, Linux/macOS:
これで動くはずなので,早速トライ!
使ってみる
適当な df の head を print するコードを書いてみようと思います.(github copilot の動作確認までなので実際には書きません.)
下記実行し,コードを書き始める.
vim print_head.py
何もでない....
下記コマンドでヘルプを見る.
:help copilot
なるほど!github アカウントの認証と有効化が必要じゃないか!?
:Copilot setup
:Copilot enable
setup 実行後,ブラウザが開くので手順に従って実行していく.
再トライ...出ない.
status コマンドで様子をみよう....
:Copilot status
Copilot: Disabled for filetype= by internal default
filetype よくわからないけど,Disabled !!!
とりあえず copilot filetype を ON にする必要がある模様.
下記を .vimrc に追記.
let g:copilot_filetypes = {
\ 'python': v:true
\}
結果,動かない.
vim の検知機能が動いていない...?
:filetype
filetype detection:OFF plugin:OFF indent:OFF
detection:OFF !!!
下記を .vimrc に追記
set nocompatible
iletype plugin indent on
syntax enable
(3つ目は任意)
:filetype
filetype detection:ON plugin:ON indent:ON
detection:ON !!!一歩前進!
再度,vim でコードを書こうとしてみる.
vim print_head.py
補完キタ!!
補完できた!!
ちなみに,status も...
:Copilot status
Copilot: Ready
Ready キタ!
おわりに
とまあ,すんなり動かせると思ったら,vim の設定を変更しないといけなかったというお話です.
まあ私が vim で書くのは簡単なコードだけなので,一旦これを使ってみます!