标签: copilot

  • neovim 配置 Github Copilot

    Github Copilot 针对 neovim 开发了一款插件 Copilot.vim

    安装之前确保 neovim 的版本比较新,另外还需要安装 node.js

    Linux / macOS  安装命令:

    
    git clone https://github.com/github/copilot.vim.git \
      ~/.config/nvim/pack/github/start/copilot.vim
      

    下载完毕后,打开 nvim 执行 :Copilot setup 

    第一次使用需要 Github 授权,

    插件会自动生成 一个 6 位字符认证码,

    在浏览器中打开插件提示的 URL,

    在这个页面填写上面的代码,

    通过授权后即可使用。

    相关命令:

    :Copilot enable //激活Copilot

    :Copilot disable //关闭Copilot

    :Copilot status //查看Copilot 状态

    :help Copilot   // Copilot 帮助文档

    问题1:

    <Tab> map has been disabled or is claimed by another plugin

    解决办法:

    因为使用了 packer 作为 neovim 的插件管理,

    在文件 ~/.config/nvim/lua/user/options.lua 中添加下面配置即可。

    vim.g.copilot_assume_mapped = true

    问题相关链接:

    [https://www.reddit.com/r/neovim/comments/sk70rk/using_github_copilot_in_neovim_tab_map_has_been/]

    问题2:

    当选择 Copilot 给出的提示代码时按键是Tab

    自动完成(cmp.lua) 选择也是Tab

    解决此冲突,可以设置选择 Copilot 建议的按键为:Ctrl + J

    然后在 cmp.lua 的配置中禁用 <C+j> 按键映射

    在 init.lua 中添加下面的配置:

    vim.g.copilot_no_tab_map = true
    
    vim.api.nvim_set_keymap("i", "<C-J>", 'copilot#Accept("<CR>")', { silent = true, expr = true })

    参考链接:

    https://www.reddit.com/r/neovim/comments/sk70rk/using_github_copilot_in_neovim_tab_map_has_been/