Tip 2Switching to Neovim
images/neovim-only.png

Neovim can be used as a drop-in replacement for Vim. In this tip, you’ll find out how to install Neovim on Debian and macOS, and how to make Neovim use your existing vimrc and Vim plugins. If you want to install Neovim on another system, Neovim’s wiki contains comprehensive installation instructions for many systems.[10]

Installing Neovim on Linux

Linux users should be able to get Neovim with their package manager. For example, on Debian, you’d install Neovim by running:

=> $ sudo apt-get install neovim

If that doesn’t work, you may need to install the Personal Package Archive (PPA):

=> $ sudo add-apt-repository ppa:neovim-ppa/stable
=> $ sudo apt-get install neovim

Alternatively, you can install Neovim as an AppImage,[12] which is a universal package that should work on most modern Linux distributions. You can get the latest nightly build from the Neovim releases page.[13] After downloading, you need to make the package executable:

=> $ curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
=> $ chmod u+x nvim.appimage

You could then launch Neovim by running:

=> $ ./nvim.appimage

If you choose this option, you may want to set up an alias so that you can launch Neovim without typing so many characters.

Installing Neovim on macOS

On macOS, you can install Neovim using Homebrew:

=> $ brew install neovim

Launching Neovim

“Neovim” is the name of the software; “neovim” is the name of the package; and the executable command is abbreviated to nvim. When you’ve installed it, launch Neovim by running:

=> $ nvim

The act of typing “vim” is probably burned into your fingers’ muscle memory. You might want to configure your shell with an alias so that typing “vim” starts Neovim instead of Vim. You could also set the $VISUAL variable to nvim, so that programs that launch a text editor (such as git commit) will use Neovim. In bash, you could set that up as follows:

 # Use Neovim as "preferred editor"
 export VISUAL=nvim
 
 # Use Neovim instead of Vim or Vi
 alias vim=nvim
 alias vi=nvim

For a couple of examples showing how $VISUAL can be useful, skip ahead to Tip 22, Using an Existing nvim Instance as the Preferred Editor.

Reusing Your Vim Configuration

For a smooth transition from Vim to Neovim, it helps to reuse your existing configuration. Neovim can load your Vim runtime configuration files, but first you have to tell it where to find them.

When Vim starts up, it looks in your ~/.vim directory for a vimrc configuration file. The equivalent configuration file for Neovim is located in a ~/.config/nvim directory and is called init.vim (:help base-directories).

You’ll have to create the configuration directory for Neovim:

=> $ mkdir -p ~/.config/nvim

Next, create and save a ~/.config/nvim/init.vim file with the following contents:

 set​ runtimepath^=~​/.vim runtimepath+=~/​.​vim​/after
 let​ &packpath = &runtimepath
 source ~​/.vim/​vimrc

Next time you launch nvim, it should load the same runtime files as vim. That means that your Vim customizations now apply to Neovim.

Vim Script Compatibility

Most Vim plugins written in Vim script should just work in Neovim. The one area where you have to be cautious is with any plugin that uses job control to perform work asynchronously. Both Vim and Neovim support this functionality, but their APIs are different. Since the job control feature is relatively new, this issue doesn’t affect many plugins.

Contextual Instructions for Neovim

Throughout this book, you’ll come across generalized instructions that look like this:

=> $ mkdir -p $VIMCONFIG/pack/bundle/start
=> $ mkdir -p $VIMDATA/undo

When running Neovim on Unix, you could execute those commands by running:

=> $ mkdir -p ~/.config/nvim/pack/bundle/start
=> $ mkdir -p ~/.local/share/nvim/undo

Alternatively, you could set the $VIMCONFIG and $VIMDATA variables for your shell. For example, in bash you would run:

=> $ export VIMCONFIG=~/.config/nvim
=> $ export VIMDATA=~/.local/share/nvim

Having set these variables, you could then run the mkdir -p $VIMCONFIG/pack/bundle/start and mkdir -p $VIMDATA/undo commands verbatim.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.158.148