DEV Community


Posted on

My Neovim Setup

Alt Text

I’m sure this is done a million times. As my first post, I thought it would be nice to document by Neovim setup or configuration. I spent a lot of time fine-tuning the configuration and I am quite pleased with my efforts. This post covers a top-level general configuration for Neovim, but in most cases it should work for Vim as well.

I have linked the plugins to their respective GitHub repos. Setup instructions are well detailed in the repos’ README file or the GitHub repo’s wiki.

Before I continue to give some details of my configuration, Neovim needs a package manager. For this vim-plug is easy to use and minimalist in configuration. To install, in a terminal:

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \

Setup of vim-plug is quite easy. In your .vimrc/init.vim, a simple configuration will include lines:

call plug#begin('~/.config/nvim/plugged')

Plug 'ncm2/ncm2'
Plug '...'

call plug#end()

The lines in between the call block will include the plugins you need to install. The string within the single-quote is the name of the Github repo and each Plug is a plugin that will be installed. The filepath within the plug#begin will have to match your path to the vim/neovim configuration. The directory name can be any name of your choice. That’s it! You have a package manager ready to use.

I will be covering few aspects to make a robust text editor for your programming needs, these are:

  • Code Completion

  • Diagnostics & Linting

  • Terminal integration

  • Git

Code Completion

For code completion, I have been using neovim-completion-manager-2 or ncm2 since version 1. Each of the source providers are separate packages and I would recommend bufword, path, ultisnips (snippet manager), vim at the minimum. For programming languages, you have two options:

  1. Install each of the ncm2 sources for the languages you will be using. Each of the sources has instructions to setup. These normally require external packages to be installed that will be needed to integrate with your editor.

  2. Install language-server-protocol source ncm2-vim-lsp (in my case) and let it do all the work. Instructions are below.

Diagnostics & Linting

For diagnostics and linting, we will use the really venerable and text editor agnostic Language Server Protocol . There are plenty of blog posts about the benefits of using LSP, primarily it provides an engine for code completion, code diagnostics, reference/definition lookup, formatting and linting. There are plenty of options that are in active development: vim-lsp, LanguageClient-neovim, coc.nvim, ale, vim-lsc. Personally, I have been using vim-lsp for my needs. Simply follow the instructions in the repo’s wiki to get setup.

I have setup vim-lsp for Ruby, Python and JavaScript. Each of them require their requisite external packages to be installed for it to work.

Tip: A way to keep your .vimrc/init.vim clean is use the ftplugin directory structure for each of programming filetypes. For instance, all my ruby mappings are stored in the ftplugin/ruby.vim file within my vim root directory. Here is an illustration of my directory structure. Respecting this directory structure will ensure the mappings will get added after your editor has loaded the necessary configurations for that filetype.

├── after
│   └── ftplugin
├── autoload
│   ├── plug.vim
│   └── plug.vim.old
├── coc-settings.json
├── ftplugin
│   ├── javascript.vim
│   ├── markdown.vim
│   ├── python.vim
│   └── ruby.vim
├── init.vim

Before you have LSP up and running, ensure you install the ncm2 source for vim-lsp. This will ensure ncm2 will lookup your language server for code completion.

Terminal Integration

Neovim’s terminal integration is one my favorite features. With the help of a plugin neoterm, it’s definitely a productivity boost and it has drastically improved my workflow. Creating terminal splits, mapping a command to a shortcut, and the occasional REPLs are few of my frequently used features of the plugin. Here are some handy tips of using a terminal with neoterm/neovim in ex mode:

  1. To open a new terminal split :Tnew

  2. Toggle open/hide terminal split :1Topen and :1Tclose . The number is the terminal number and it increments for every new terminal you create. Creating every new terminal creates its own vim buffer and allows you to treat them like actual buffers.

  3. Sending a command to a particular split :1T bundle exec rails s or :2T bundle exec rails c

  4. Map a run command to a shortcut :Tmap ruby foo.rb , this will map the run command to ,tt in normal mode

  5. TREPLSendFile and TREPLSendLine will send the respective context to the programming language’s interpreter. pry and irb for Ruby, ipython for Python.


For Git, I am using Tim Pope’s awesome vim-fugitive. The commands are well documented. Here are my frequently used commands:

  1. :Gstatus and its various sub-commands. This opens a preview window of your modifications, and you can view the various sub-commands by pressing g? in the preview window. cc and ce are my frequently used sub-commands to commit and amend.

  2. :Gdiff for your diff needs

  3. :Gpush and :Gpull

  4. :Gblame for that crucial who dun it view of your files.

Closing Thoughts

This guide isn’t newbie friendly, so I recommend vimtutor and similar training techniques to get accustomed to vim land. Plugins are a nice addition to vim making it more user friendly at the same time. Some pros will scoff at the idea of using plugins. There is no harm in them as long as it works for you. Neovim or Vim is a matter of personal choice. I chose Neovim, because I feel its leading the development of bringing new features to Vim. Neovim 0.4.0 release brought floating windows, a new lua init support, multi-grids and several other improvements.

Top comments (2)

notalex profile image

Late to the party! 😅 Interesting read. Do you have a dotfiles repo?

vshl profile image

Hi Alex, I do have a repo:

It's a bit of a mess, I'd advise cherry picking as per your need and not to blindly copy it.