Switching to Neovim


I recently switched from Vim to Neovim. One year later, I’m delighted. Neovim is snappier, works better out of the box, and has been perfectly compatible with my Vim configs!

Under the hood, Neovim supports asynchronous execution. This means tools like linters run in the background without slowing down the editing experience.

Setting Up Neovim

Installing Neovim with Python Support

  1. On Mac, $ brew install neovim
  2. Add python support, $ pip install neovim

if you have python2 and python3, then run pip2 and pip3 install

Launch neovim with nvim from the command line.

To verify correct installation, run :CheckHealth from Neovim.

Configuring Neovim

  • .config/nvim/init.vim is the neovim equivalent of a .vimrc
  • I sync my configurations using a dotfiles repo on GitHub. This backsup my configurations and helps quickly setup any machine I use.
  • I manage plugins using vim plug. Vim plug keeps plugins in init.vim along with configurations.
    • running :PlugInstall will search init.vim for plugins to install

Editing

One example of the saner defaults is the cursor: thin means you’re in insert mode.

  • indentation and syntax highlighting: polyglot
  • markdown spell check: add autocmd FileType markdown setlocal spell to init.vim
  • linter in the background: ale supports multiple languages
  • auto-completion using tab: supertab and deoplete to make completion asynchronous

Working with Multiple Files

Vim and Neovim unfortunately have several confusing concepts for having multiple files open. A window is a view into a buffer. Multiple windows can view the same buffer. There are also tabs, which are unfortunately laggy if you have too many open. Instead, what we think of tab in most applications, is actually a buffer. That’s what I use to view multiple files.

I configured tab to switch buffers by adding:

nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>

Two plugins make file navigation easy

  • nerdtree gives file navigation similar to sublime and Intellij. Handy for a view of a project’s file structure: Nerdtree

  • Ctrlp. Just type Ctrl-P for fuzzy file matching, it’s wonderful: Ctrlp

Searching in and across Files

  • Ack, a very fast grep across a set of file. By default, this is set to the current directory. To search use :Ack [pattern]

This searches across files in the directory and supports regex for more advanced searches.

One year later, Neovim gets a big thumbs up!