ubuntu环境下vim+copilot的部署与使用

部署

在linux环境下有两种方式让vim可以使用vim,一种是使用neovim,还有一种直接使用vim.

直接使用vim时vim版本要大于9.0.0185,nodejs>18.0

更新 vim 版本大于 9.0.0185

1
2
3
4
5
6
# 安装 依赖包 add-apt-repository
$ apt install software-properties-common
# 添加 Vim 的 PPA
$ add-apt-repository ppa:jonathonf/vim
#更新系统
$ apt update

安装node.sj

1
2
3
4
5
6
7
8
9
# 删除老的
$ apt remove nodejs
$ apt autoremove
# 下载noddejs 安装20版
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# 安装20版
$ apt-get install -y nodejs
# 验证版本
$ node -v

安装 github/copilot.vim

1
git clone https://github.com/github/copilot.vim.git ~/.vim/pack/github/start/copilot.vim

使用

启用copilot

1
2
3
4
5
6
1. 启动 vim
vim
2. 部署 copilot并认证 ,在启动后的vim 窗口输入下面命令
:Copilot setup
3. 启动 copilot, 在vim命令窗口执行如下命令
:Copilot enable

vim copilot 配置

1
2
3
4
5
1. 修改默认tab键接收建议为ctrl+j
vim ~/.vimrc
添加以下内容
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true

问题

  • Invoke :Copilot setup to authenticate and enable GitHub Copilot.
    1
    2
    ```
    - Failed to open browser. Visit https://github.com/login/device
    此时是需要通过网页验证copilot账号信息,在错误行的上一行还有一行下列信息
    First copy your one-time code: XXXX-XXXX

通过网页打开 https://github.com/login/device, 然后输入上面提示的xxxx-xxxx密码等待通过认证即可。

```

参考文档

https://docs.github.com/zh/billing/managing-billing-for-github-copilot/managing-your-github-copilot-subscription-for-your-personal-account

https://docs.github.com/zh/copilot/getting-started-with-github-copilot?tool=vimneovim#prerequisites-3

https://github.com/orgs/community/discussions/8105


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!