Plugin management in Neovim and GitHub Copilot introduction notes#
This is a record of building an auto-completion environment by installing a minimum number of plugins in the environment immediately after installing Neovim. In the first stage, we adopted vim-plug as our plugin manager and introduced GitHub Copilot as the first plugin.
Background and purpose#
I added GitHub Copilot for its strong autocompletion, while keeping the overall approach of making Neovim lightweight, personal, and easy to grow one plugin at a time.
Copilot is now available in the free tier, making it the perfect plugin to try out easily.
Installing vim-plug#
First, we will introduce the plugin management tool vim-plug. I am aware that the lua-based lazy.nvim is rapidly developing as a plugin management tool, but vim-plug has over 10 years of experience and a large amount of information, and its specifications are outdated, making it an easy environment for trying out plugins from vanilla.
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
In init.vim write:
call plug#begin('~/.local/share/nvim/plugged')
" GitHub Copilot プラグイン
Plug 'github/copilot.vim'
call plug#end()
vim-plug basic commands and timing of use#
:PlugInstall– Install a plugin:PlugUpdate– Update an existing plugin:PlugClean– Delete plugins that are no longer needed (no confirmation with !)
When setting up for the first time, just run :PlugInstall.
If you want to automate it, you can also run it from the command line as below, so please refer to it:
nvim --headless +PlugInstall +qall
Deploying and setting up GitHub Copilot#
Reasons for choosing Copilot as a plugin:
Available for free with a GitHub account
Provides highly accurate completion for Python and other languages
Instead of one line, Multi-line function definition completion is also possible
The necessary files have already been downloaded by writing the above init.vim and executing PlugInstall. If you want to work with copilot, you will need to set it up the first time:
:Copilot setup
Open the displayed URL in your local browser and enter the authentication code to complete the linkage.
How to deal with errors during installation#
Node.js required: If you get
Node.js not found in PATHduringCopilot setup, you need to install node.js. You can also usesudo apt install -y nodejs npm, but in this article, we installed Node.js using nvm. nvm is a Node.js version control tool that allows you to easily switch between multiple Node.js versions.curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash export NVM_DIR="$HOME/.nvm" . "$NVM_DIR/nvm.sh" nvm install --lts
Also, add the following to
.bashrcor.zshrcso that you can use Node.js on subsequent logins:export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Unable to open browser in SSH connection environment: Copy the code and URL that are displayed when you run
:Copilot setup, and open the following URL in your local PC’s browser:URL: login/device
All you have to do is enter the authentication code displayed by Neovim (e.g.
ABCD-EFGH) into the input field displayed by your browser.Authentication code does not pass: It may have expired, so run
:Copilot setupagain.Ignore ‘xdg-open’ error in SSH connection environment: Error SERVER_REQUEST_HANDLER_ERROR: Vim:E475: Invalid value for argument cmd: ‘xdg-open’ is not executable can be safely ignored.
Ensure Setup is completed: Restart Neovim and try running the following command:
:Copilot statusIf
Readyis displayed, the link with Copilot is complete.
Points to note when introducing complementary plug-ins in the future#
Many completion engines (e.g. nvim-cmp) use the <Tab> key to select and confirm completion candidates. On the other hand, GitHub Copilot is also set to accept completion using <Tab> by default, so if both are enabled at the same time, a keystroke conflict will occur.
By changing Copilot’s key mapping in advance for future expansion, it will be easier to coexist with other completion engines.
You can change Copilot’s completion acceptance to <C-J> (Ctrl+J) by adding the following to init.vim:
let g:copilot_no_tab_map = v:true
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
Attention
If you apply this setting, don’t forget to set Copilot’s completion acceptance key to <C-J>.
summary#
Build an environment where you can try out vim plugins from scratch using vim-plug.
Just installing Copilot is powerful enough
Adjust the key mapping in consideration of trying various plugins in the future.
Article information
- Post date:
2025-05-08
- author:
Mr. Takagi