Configure Neovim

In this post, I’d like to show you how to start customizing your Neovim editor.

Video tutorial

You might notice that I’m typing nvim, that is Neovim’s binary. I suppose it’s so Neovim can coexist with Vim, but I only use one of them, so let’s do something about that so that we can simply type vim. We can achieve this by creating an alias in our bash configuration file: alias vim=nvim.

On Linux, Neovim will look for the settings file in ~/.config/nvim/. The first step, then, is to make sure the directory exists.

mkdir -p ~/.config/nvim/

The configuration file should be named init.vim. Let’s create it and put a few settings in it:

vim ~/.config/nvim/init.vim

set clipboard=unnamedplus " This setting will integrate vim's clipboard with the system's clipboard
set number                " This one will indicate vim to show lines numbers on the left 
set ignorecase            " This setting will make our search case insensitive
set incsearch		  " this one allows us to see results as we type our search

This is only a sample, I’ll leave it to you to customize the editor to your liking.

One last thing, Vim allows you to extend its functionality via plugins, and the easiest way to use one is with a plugin manager. Let show you how to set up vim-plug. One of the most popular and the one I use. You can install the plugin like so:

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

Now, let’s configure the plugin manager:

call plug#begin()
" Plugins go here
call plug#end()

One plugin that I use all the time is vim-surround. It facilitates working with “surroundings”: things like parentheses, brackets, HTML tags, etc. This is how you add a plugin:

" Sample plugin
Plug 'tpope/vim-surround'

Restart the editor and install the plugins with :PlugInstall. Close the editor and open it again, and you should be able to start using the plugin. Let me show you:

This is a text with (parentheses).

Position the cursor on one of the parentheses and type ds( and both parentheses will go away.

All right, I believe this is a good start. Go ahead and customize vim to your liking. Thank you for reading, until next time.


Posted

in

by

Tags: