ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • NeoVim Install And Setup for Rust Development
    Vim_Editor_IDE/Vim_.vimrc설정 2022. 2. 22. 12:03
    728x90

    https://www.reddit.com/r/learnrust/comments/smh8l0/neovim_install_and_setup_for_rust_development/?utm_source=share&utm_medium=ios_app&utm_name=iossmf

    NeoVim Install And Setup for Rust Development

    I had such a time trying to get [NeoVim](https://neovim.io/) set up on my Linux machine for Rust development (well study and practice for now) I...

    www.reddit.com





    NeoVim Install And Setup for Rust Development

    I had such a time trying to get [NeoVim](https://neovim.io/) set up on my Linux machine for Rust development (well study and practice for now) I figured it might be worthwhile to do a write up on what all is needed.  Working all this out prompted me to do what I probably should have done from the start; Setup a VM for Rust development.

    For the purpose of this write up, I am using Ubuntu 21.10 set up in a VM.  So I start with a blank slate, install Rust, Neovim, etc.

    # Installations

    **Install Rust**

    You probably all know how to do this, but for the sake of completeness the [Rust](https://www.rust-lang.org/) website has the instructions if you are not on Linux.  If you are, its a simple command:

        curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

    Chose the default install unless you have reason to do otherwise.

    **Install Rust Analyzer**

    The Rust Analyzer was a point of pain for me, but primarily because all the write ups I found out there installed it in a completely different location.  I eventually wised up and put it in with the `~/.cargo/bin` location so that it was not only with everything else, but in my PATH for everything rust related:

        curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip -c - > ~/.cargo/bin/rust-analyzer

    After you have that installed, you need to make it executable:

        chmod +x ~/.cargo/bin/rust-analyzer

    **Install NeoVim**

    Next up, install NeoVim.  The current release which is v0.6.1 can be found on their [Github](https://github.com/neovim/neovim/releases) page.  For Linux I downloaded `nvim-linux64.tar.gz`.  Unless you have set things up differently, this should download to your `~/Downloads` folder.  After it has downloaded you will need to open up a terminal session there and extract the file then move it to `/usr/local/bin/nvim`.

        tar -xzf nvim-linux64.tar.gz
        sudo cp nvim-linux64/bin/nvim /usr/local/bin/nvim

    Don't close the terminal just yet.  There are a few more things that need to be done.  Some instructions called for a *.vimrc* file in your Home directory.  I *assume* this is supposed to be similar to a *.profile* or *.bashrc* file for the default terminal.  However, I have not used it as such yet, but it needed to be created due to some instructions that soon follow, so I created it.  I suppose once I am more acquainted with NeoVim, I will use it for its intended purpose.  To create the file, from your open terminal session run the command:

        touch ~/.vimrc

    Again, don't close the terminal session just yet, we have a couple more installs to do.

    **Install NodeJS, NPM and Python NeoVim**

        sudo apt install nodejs npm python3-neovim

    NPM is a monster install all things considered and will likely take a minute or two to complete.  Once all that has completed, keep the terminal session open, there is more work to do.

    **Configure NeoVim Plugins**

    At last, start NeoVim by typing `nvim`.  Once you are in NeoVim, run the following commands:

        :call mkdir(stdpath('config'), 'p')
        :exe 'edit '.stdpath('config').'/init.vim'

    The last command will create the `init.vim` file that we are going to add some configuration to.  Copy the following and add it to the file:

        set runtimepath^=~/.vim runtimepath+=~/.vim/after
        let &packpath = &runtimepath
        source ~/.vimrc
        
        call plug#begin(stdpath("data") . '/plugged')
        Plug 'neoclide/coc.nvim', {'branch': 'release'}
        call plug#end()

    Now, save and close the file with `:wq`.  Don't close the terminal just yet.  We have some more commands to run and we are going to come back to NeoVim.  Next, we setup the plugins for NeoVim.  Run the following command:

        curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

    Once that has done, go back into NeoVim with the command `nvim`.  Once NeoVim is open, run the following commands:

        :PlugInstall
        :CocInstall coc-rust-analyzer

    Once that is all done, you can exit out of NeoVim.  If I recall you have to use `:q` twice to get back out.  There is one last file to create and add some configuration to so that CoC can find Rust Analyzer.  From the terminal session run the command:

        touch ~/.config/coc/coc-settings.json

    There is a way you can add text to that file without having to manually open it, but I was already in the *.config* folder watching what was going on, so I just manually opened the *coc-settings.json* file and added the following:

        {
        "rust-analyzer.server.path": "/home/USERNAME/.cargo/bin/rust-analyzer"
        }

    Be sure to change *USERNAME* to whatever your Linux user name is.  Recall, at the beginning we put the Rust Analyzer in the *.cargo/bin* directory so that keeps everything nice and neat and is already in your PATH so no need to resource BASH or add any new PATH variables.

    Now, you can open up a Rust file in NeoVim and can edit it and get code completion.  I'm not sure why so much is needed to configure a command line text editor to work with a language.  VSCode sets up much easier, but I really wanted to get more comfortable to doing such development using a terminal text editor.

    Don't ask me how to set up other plugins at this point, this was enough work figuring out, LOL.  Though, I hope this is helpful to someone.  I also hope that perhaps there are those out there with more knowledge that can contribute to streamlining this a bit or a lot if needed.  Seems like a lot of work to go through but it is what finally got everything working for me.

    If this turns out to be the proper way to do it all, I can turn this all into a markdown document and/or PDF that if someone wishes to do so, can host somewhere that can be pointed to for others.  However, if I took the ***really*** long way to grandma's house, please be kind and let me know what I can do to improve the instructions.

    Enjoy!

    반응형
Designed by Tistory.