vim copilot插件安装使用

copilot简介

在使用不熟悉的开发语言或函数库进行开发工作时,虽然可以通过阅读开发文档或示例代码的方式学习开发,但这种方式学习成本较高、效率较低,且后续不一定会用上。
GitHub Copilot是一个由GitHub开发的机器学习工具,可以为开发者提供代码补全和自动生成的功能。通过分析大量的开源代码库,Copilot可以推测出开发者的意图,并生成适合当前上下文的代码段。该工具官方仅提供Visual Studio和Visual Studio Code插件,但也有开发者在Github上提供了vim插件版本,这里记录下vim copilot插件在RHEL上的安装过程。

前提条件

  1. 具有 GitHub Copilot 使用权限    :   可通过GitHub学生认证免费使用
  2. vim版本不小于9.0.0185   :   可参考【RHEL】三分钟启动完整版vim——vim9 huge编译安装 安装vim9.1

安装步骤

  1. 安装nodejs (要求nodejs版本大于16)
    可从nodejs官网下载安装,也可以在bash中复制下述代码直接安装nodejs 20版本
# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# download and install Node.js
nvm install 20

# verifies the right Node.js version is in the environment
node -v # should print `v20.12.0`

# verifies the right NPM version is in the environment
npm -v # should print `10.5.0`
  1. 下载copilot插件
    可从GitHub仓库下载,也可以在bash中复制下述代码直接放到vim默认文件夹
git clone https://github.com/github/copilot.vim.git \
  ~/.vim/pack/github/start/copilot.vim
  1. 打开vim输入 :Copilot setup,根据提示复制8位设备码,在打开的网站页面粘贴绑定设备后即可使用

  2. 在输入模式利用<Tab>键快速输入补全的代码,默认情况下Copilot需要在指定的filetype下才能使用,可通过配置文件调整,也可以在创建新文件后先指定文件类型,如:set filetype=c,通过:Copilot status指令查看为ready后即代表补全可使用。

在这里插入图片描述

  1. 使用Copilot生成的代码(忽略缩进)
    在这里插入图片描述

  2. 除了在输入模式利用<Tab>键快速输入补全的代码外,输入:Copilot help可以看到更多用法。如:Copilot status查看Copilot状态,:Copilot panel开启一个专用的Copilot对话窗口,:Copilot enable启用Copilot等。
    在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Vim YouCompleteMe安装步骤如下: 1. 安装Vundle件管理器,可以通过以下命令进行安装: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 2. 在.vimrc文件中添加以下内容: set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " YouCompleteMe件 Plugin 'Valloric/YouCompleteMe' " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required 3. 打开Vim,运行以下命令进行安装: :PluginInstall 4. 安装完成后,进入YouCompleteMe件目录,运行以下命令进行编译: cd ~/.vim/bundle/YouCompleteMe ./install.py --clang-completer 5. 编译完成后,重新打开Vim即可使用YouCompleteMe件。 ### 回答2: Vim YouCompleteMe是Vim编辑器的一个强大的自动补全件,它可以在你输入时提供不同类型的自动完成选项,如变量名、函数名、类名等。它支持多种编程语言,包括C、C++、Python、JavaScript等。下面是如何安装YouCompleteMe件。 1.安装vim件管理器Vundle:从https://github.com/VundleVim/Vundle.vim下载最新的Vundle源代码。将下载的文件解压,并将其放置在~/.vim/bundle/Vundle.vim目录下; 2.加载YouCompleteMe件:在vim配置文件(.vimrc)中,添加以下代码: `set rtp+=~/.vim/bundle/Vundle.vim` `call vundle#begin()` `Plugin 'Valloric/YouCompleteMe'` `call vundle#end()` 3.编译YouCompleteMe件:执行以下命令来编译YouCompleteMe: `cd ~/.vim/bundle/YouCompleteMe` `./install.py --clang-completer`(如果你想支持其他语言,可以在安装使用其他的选项) 4.重启Vim:重新启动Vim。 5.开启YouCompleteMe件:在命令模式下,执行以下命令来开启YouCompleteMe件: `:PluginInstall` 6.设置YouCompleteMe件:在vim配置文件(.vimrc)中,添加以下代码来设置YouCompleteMe件: `let g:ycm_min_num_of_chars_for_completion=2` `let g:ycm_autoclose_preview_window_after_completion=1` `let g:ycm_collect_identifiers_from_tags_files=1` `let g:ycm_complete_in_comments_and_strings=1` 以上是YouCompleteMe件的安装步骤及设置方法,希望对您有所帮助。 ### 回答3: 1. 安装vim 在开始安装youcompleteme件之前,必须确保vim已经被正确地安装在您的电脑上。对于Ubuntu和Debian用户,可以使用以下命令来安装: ``` sudo apt-get install vim ``` 2. 安装Vundle Vundle是一个用于管理vim件的工具。在安装youcompleteme之前,我们需要先安装Vundle。可以使用以下命令来安装: ``` git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 3. 安装youcompleteme 安装youcompleteme需要先确保一些依赖项已经被安装在您的电脑上。对于Ubuntu和Debian用户,可以使用以下命令来安装: ``` sudo apt-get install build-essential cmake python-dev python3-dev ``` 在安装完这些依赖项之后,我们需要进入vim使用Vundle安装youcompleteme件。 首先,在命令行上输入vim并按回车键,进入vim。 其次,在vim中,按下"Esc"键来进入命令模式。 然后,输入以下命令,以从您的vimrc文件中安装youcompleteme件: ``` :PluginInstall ``` 在您输入该命令后,Vundle将开始下载并安装youcompleteme件。此时需要安装件的依赖项,输入以下命令: ``` cd ~/.vim/bundle/YouCompleteMe python install.py --clang-completer ``` 这将花费一些时间来完成youcompleteme件的安装。 4. 配置youcompleteme 安装youcompleteme后,您需要在.vimrc文件中进行一些配置。例如,您可以设置允许youcompleteme在打开文件时立即启动自动补全。添加以下设置: ``` autocmd InsertEnter * if !&completefunc | setlocal completefunc=YouCompleteMe\|UltiSnips#Complete | endif ``` 完成上述步骤后,youcompleteme件将在您的vim中运行,让您更加高效地进行编码工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjh776a68

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值