0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vim で github copilot を使う

Posted at

vim で github copilot を使う

はじめに

最近ようやく github copilot を契約し,私は最強になってしまったわけです.
ただ,私は vscode 以外に vim も使うので,vim で動かす方法・詰まったところを備忘録として残しておきます.メモです!

動作環境

  • Mac
  • Vim version 9.1.754

インストール方法

copilot.vim によると下記の手順で OK.

  1. Install vim
  2. Install Node.js
  3. 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
      

これで動くはずなので,早速トライ!

使ってみる

適当な df の head を print するコードを書いてみようと思います.(github copilot の動作確認までなので実際には書きません.)
下記実行し,コードを書き始める.

vim print_head.py

image.png

何もでない....

下記コマンドでヘルプを見る.

:help copilot

image.png

なるほど!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

image.png

補完キタ!!

タブを押す.
image.png

補完できた!!

ちなみに,status も...

:Copilot status
Copilot: Ready

Ready キタ!

おわりに

とまあ,すんなり動かせると思ったら,vim の設定を変更しないといけなかったというお話です.
まあ私が vim で書くのは簡単なコードだけなので,一旦これを使ってみます!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?