Neovim, Week 1

I’ve been a longtime user of Vim emulation in text editors like Sublime Text, Atom, and IntelliJ IDEA, but haven’t gone so far as to use Vim itself for work. With the recent stable release of Neovim 0.1.x, and its promise of a faster, leaner implementation of the storied editor, I decided it might be time to move beyond being a Vim poser and try to become a competent and confident user.

My hope is that these posts will be helpful for people like me who are relatively experienced at using Vim-modes in other editors and want to start their journey with Neovim. In other words, this is not the story of an experienced Vim user making the move to Neovim; I’m starting from scratch, with almost no previous knowledge of Vim, .vimrcs and the Vim plugin ecosystem.

Currently, I use Atom (and atom-vim) at work, where I mainly write JavaScript, but also experiment with other languages like Elm and PureScript. As an initial goal, I want to configure my Neovim to have the same basic functionality that I rely on in Atom:

  • Full-text search (e.g. ⌘⇧F)
  • Fast access to files (e.g. ⌘P)
  • Tree view
  • Syntax highlighting for ES6 and JSX
  • ESLint integration
  • Highlighting occurrences of symbols (e.g. through the highlight-selected package)

Installing Neovim

I work on a Mac, so I installed Neovim using the homebrew installation instructions. Although I mainly open the app with nvim on the terminal, I also installed the Neovim.app GUI just to see how it compared with MacVim, the OS X GUI for classic Vim.

Installing vim-plug

To get some plugins for Vim, I needed a plugin manager. I was already aware of plugin managers like Vundle and Pathogen, but decided to go with vim-plug after watching Nick Nisi’s presentation, as it seemed to be built to take advantage of Neovim’s asynchronous plugin API. In other words, it promised to work faster than the older plugin managers.

On it’s Github page, there is a one-liner curl command that will download the script and place it in the ~/.config/nvim/autoload folder:

$ curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

The next I had to do was create a ~/.config/nvim/init.vim and start it off with these two lines:

call plug#begin('~/.config/nvim/plugged')
" Plugins will go here in the middle.
call plug#end()

To test it out, I opened nvim and ran :PlugInstall, which opens a pane on the left, where it shows the installation of progress of all the plugins (at this point, I wouldn’t have had any).

Getting the first few plugins

Supposedly, most plugins developed for Vim should work in Neovim. After watching this other video on Vim, I identified a few plugins I thought I should install.

Fuzzy file search

In the video, ctrlp.vim was suggested as the plug-in to use to get the Sublime/Atom-style ⌘P file search functionality. However, after reading this Reddit thread, I decided to go with fzf, which is actually a Go program that comes with bindings to Vim and zsh, among other things.

After following the instructions to install and put fzf on my path, I simply added these lines to init.vim:

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

Nerdtree

Nerdtree is a tree explorer for your files, similar to the left-hand panel you can toggle in Atom with ⌘/. In the vim-plug GitHub page, there is an example of the on-demand loading feature, which will delay loading the plugin until it is asked for:

So in init.vim, we can install Nerdtree with dynamic loading with this line:

Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

UPDATE: After learning more about the built-in netrw plugin from this Vimcasts episode, I decided to delete Nerdtree. I’m going to look into using vim-vinegar.

Full-text search with ag.vim

In the video, ag.vim was suggested as a search tool. This is an interface to the ag (The Silver Surfer) command line tool. I already had this installed via brew, so the only thing to do was add this line to my init.vim:

Plug 'rking/ag.vim'

Summary

So this is what my init.vim looks like with these plugins:

call plug#begin('~/.config/nvim/plugged')
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'rking/ag.vim'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
call plug#end()

To invoke fuzzy file search with ⌃P, I added this extra key mapping:

nnoremap <C-p> :FZF<CR>

Which I found doing a code search for <C-p> :FZF<CR> on GitHub. (I have no idea what nnoremap means!)

Next Steps

In the next post, I’ll document my initial experience with this setup see how many more items I can check off on my list.