DEV Community

Vee Satayamas
Vee Satayamas

Posted on

Enable Rust autocomplete in Neovim

Prerequisite

I use Ubuntu 20.04 and I have already install node.js.

Install neovim

apt-get install neovim
Enter fullscreen mode Exit fullscreen mode

Install vimplug

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
Enter fullscreen mode Exit fullscreen mode

(source: https://github.com/junegunn/vim-plug)

Setup vimplug

nvim $HOME/.config/nvim/init.vim
Enter fullscreen mode Exit fullscreen mode

In $HOME/.config/nvim/init.vim

call plug#begin(stdpath("data") . '/plugged')

call plug#end()
Enter fullscreen mode Exit fullscreen mode

Install coc.vim

In $HOME/.config/nvim/init.vim

call plug#begin(stdpath("data") . '/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Enter fullscreen mode Exit fullscreen mode

In nvim,

:PlugInstall
Enter fullscreen mode Exit fullscreen mode

Install rust-analyzer

mkdir .local/bin
curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o ~/.local/bin/rust-analyzer
chmod +x ~/.local/bin/rust-analyzer
Enter fullscreen mode Exit fullscreen mode

(source: https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary)

Install coc-rust-analyzer

In nvim,

:CocInstall coc-rust-analyzer
Enter fullscreen mode Exit fullscreen mode

Alt Text

Setup coc

In $HOME/.config/nvim/coc-settings.json

{"rust-analyzer.server.path": "/home/YOURNAME/.local/bin/rust-analyzer"}                                                                                                         
Enter fullscreen mode Exit fullscreen mode

Please replace YOURNAME with your name.

Open a source code in Rust

It should work.

Alt Text

Top comments (0)