A Better Vim
I love Vim, it’s been my text editor for over a year and a half now and I am constantly learning new things about it. The beauty of it is that once you’ve learned the basic language (eg.: delete the next two words: 2dw) you can easily start editing text without ever touching your mouse, the more advanced commands being only a :help away!
Now while vim is a great text editor, thats all it is. If you want modern IDE features (While still keeping modal editing) you will need to either switch to an IDE with a vim emulation or start downloading plugins. Lucky for you, vim has a vibrant plugin scene, which means that you can adapt its base features to pretty much any language you’d want. Even more “enterprise” and IDE bound languages are available thanks to plugins like Eclim for java and Omnisharp for .net development.
Unfortunately, this is also vim’s Achille’s heel.
The problem
The reason for this is that when you execute a plugin the code is run synchronously. This means that for plugins that require a lot of computation, for example a linter, the ui will often hang, forcing you to wait until the execution is over before you can resume editing. If you have certain plugins executing on the fly, this can quickly become a bother.
The best solution I’ve seen so far for this problem is the one used by the YouCompleteMe plugin. It offers on the fly code linting for c and c++ code and it works very well, even though installing it is more of a hassle than for other plugins. It works by implementing a server/client setup where the linting is done on a python backend while the errors are sent to the vim client. This allows for lightning fast asynchronous linting.
But since this only works for c and c++, it is not a good solution. When it got too annoying I fixed this by switching over to Spacemacs. This Emacs extension is basically a whole new editor and I recommend it if all you want if an out-of-the-box IDE with modal editing. Emacs has asynchronous plugin execution so the problem is solved.
But I always felt a little bad about leaving vim behind.
The solution
Here is where things get interesting, behold Neovim. Neovim is a fork of vim bent on modernising the code base and refactoring the way vim interacts with plugins and external applications. It comes with a few cool perks:
It’s basically a library
Thanks to the msgpack api, it is possible to interact with neovim through different languages and even embed it inside another application.
Good defaults
Vim can be intimidating to newbies, neovim makes it act a little more like a modern text editor
Vim backwards-compatibility
So anything that works in vim, works in neovim (Except maybe a few really old operating systems)
Plugins run asynchronously
Now you’re telling me; doesnt that solve our problem?
Ok so we have asynchronous plugins, but if it retains vim compatibility, arent those old plugins going to run synchronously? Unfortunately the answer is yes. That means we need new or updated plugins, thankfully there is a wiki page that details plugins that are adapted for neovim.
My personal setup
The main reason I wrote this post is because I wanted to share my personal configuration, so without further adue:
Make sure your terminal supports true colors, or else it might look weird
I use Simple Terminal.
Install Neovim
I am using Void-Linux as my operating system so it was as simple as
sudo xbps-install -S neovim, if you’re using another distribution, follow the standard installation instructions.Where is the .vimrc?
The rc file is now located in
$XDG_CONFIG_HOME/nvim/and is namedinit.vim. So create that file and folder if need be and open it with any text editor.General configuration
Before adding something to your config file, I highly recommend reading about it with
:help OPTIONNAMEI want to have syntax coloring, thus I need to activate a few options:
syntax on filetype plugin indent onI also prefer a black background:
set background=darkIf you prefer having spaces instead of tabs there are a few more options:
set autoindent set backspace=indent,eol,start set complete-=i set smattab set tabstop=4 set shiftwidth=4 set expandtabAnd last but not least encoding an numbered lines:
set encoding=utf-8 set numberPlugin Manager
To turn Vim into a light IDE, we will need a few plugins. A plugin manager makes our job much easier, Vundle is one of the most popular plugin managers, but I prefer to use Vim-Plug. It’s a minimalist package manager that is neovim aware, that means it can load plugins asynchronously, making startups much faster in certain cases. Follow the installation instructions (Install it in $XDG_CONFIG_HOME/nvim/autoload/ instead of .vim/autoload/).
Plugins
So now that we have a good setup, lets add a few plugins, here is a list of the plugins I use (Use it as an example on how to install plugins):
call plug#begin('~/.config/nvim/plugged')
" Pandoc / Markdown
Plug 'vim-pandoc/vim-pandoc', { 'for': [ 'pandoc', 'markdown' ] }
Plug 'vim-pandoc/vim-pandoc-syntax', { 'for': [ 'pandoc', 'markdown' ] }
" General
Plug 'benekastah/neomake'
Plug 'Shougo/deoplete.nvim'
Plug 'Raimondi/delimitMate'
Plug 'altercation/vim-colors-solarized'
Plug 'ervandew/supertab'
" Haskell
Plug 'neovimhaskell/haskell-vim', { 'for': [ 'haskell', 'cabal' ] }
" Lisp
Plug 'vim-scripts/paredit.vim', { 'for': [ 'scheme', 'lisp', 'commonlisp' ] }
call plug#end()
The { 'for': [ 'haskell', 'cabal' ] } lines are so that vim-plug only loads plugins when the filetypes corresponding to those languages are used.
I will only detail a few of these, I have not really tested some of the more language-specific ones
Neomake
Neomake fullfills the same job Syntastic does for Vim, except it is capable of running the various linters it supports asynchronously. Add this to your init.vim so it lints your files automatically when you save:
autocmd! BufWritePost * Neomake
Neomake has support for custom makers, but supports a bunch of linters out of the box, you simply have to install them on your computer.
Deoplete
Deoplete is an on the fly auto complete for your local buffer. I find it is fast and easy to use, to install properly you want to first install the python neovim library: pip3 install neovim and then run :UpdateRemotePlugins inside neovim after you’ve installed/updated deoplete. I recommend adding the following line to your init.vim: let g:deoplete#enable_at_startup=1.
Supertab
Supertab is a simple plugin so you can cycle through deopletes auto-completion with the tab key.
DelimitMate
Really cool plugin to automatically match any brackets, parentheses or quotes when you’re typing.
Solarized
If you’re not familiar with the Solarized colorscheme, go look at it now! It’s a very pretty colorscheme thats easy on the eyes and features the same basic palette for its light and dark modes. You only need to add colorscheme solarized in your init.vim after installing it. (Will not work well without a terminal that supports true colors).
Thats it for now folks! If I do some changes or notice any errors I’ll update this post, I do not have any comment system in as I’m in the process of switching this website over to Hakyll, so if you want to discuss it I recommend using Lobsters or Hacker News.