LinkedIn Sourceforge Twitter

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

moving from vim to nvim

Posted on 2019-03-08 13:47:00 from Vincent in OpenBSD nvim

I'm a vim user since several years. This blog explain how I move to neovim.


I'm using Vim and Gvim as text editor for nearly all my tasks since several years; from editing a config file to write scripts and programs.

I'm not a "true" developer, but I'm doing lot of python's scripts and programs. For that purpose I've configured my vim environment with lot plugins facilitating such python developments.

I'm user of ranger, so I'll also explain how nvim can fit this environment. Anyhow, what I did there, could be re-used for several other file-manager.

Installation of nvim plugins


As often on OpenBSD, a simple command allows you to install the program:

doas pkg_add neovim

The current version I'm using is neovim-0.3.1 on OpenBSD 6.4

If not yet done, you also need some python pre-requisites:

doas pkg_add py3-pip
pip3.6 install neovim

I'm focusing on python3 instead of python2.

Configuration file of nvim

As described on the nvim documentation, most of configuration elements must reside in a file called ~/.config/nvim/init.nvim

Let's first create that directory:

mkdir ~/.config/nvim

Here after I share my init.vim file.

But before using it we have one pre-requisite: vim-plug
A tool that will allow us to easily install nvim's plugins

Install vim-plug

To install this kind of packet manager, we have to perform 2 actions:

mkdir -p ~/.local/share/nvim/site/autoload/; cd ~/.local/share/nvim/site/autoload/

Once that done, we will be able to install and update each of our nvim plugins via simple commands like: PlugInstall, PlugUpdate

Install plugins

For my setup and needs, I need the following plugins:

call plug#begin()
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'

Plug 'tpope/vim-surround'

Plug 'sbdchd/neoformat'

Plug 'zchee/deoplete-jedi' 
Plug 'Shougo/deoplete.nvim'
call plug#end()

Each line between "call plug#begin()" and "call plug#end()" are the plugins we are willing to install

Copy/paste those line in your brand new init.nvim file located in the folder ~/.config/nvim/

Then starts nvim and type:


You will have something like this:

Updated. Elapsed time: 19.832332 sec.

Finishing ... Done!
ultisnips: Resolving deltas: 100% (216/216), done.
neoformat: Resolving deltas: 100% (210/210), done.
deoplete.nvim: Resolving deltas: 100% (324/324), done.
vim-surround: remote: Total 30 (delta 7), reused 20 (delta 1), pack-reused 0
deoplete-jedi: remote: Total 60 (delta 8), reused 31 (delta 1), pack-reused 0
vim-snippets: Resolving deltas: 100% (169/169), done.

Before leaving nvim, I suggest you to perform a last command:


That's it !!! Your plugins are installed. You can quit nvim by doing: ":q" 2 times

Before finalizing this installation part, you have to finalize the setup of 2 of those plugins. Indeed, for "neoformat", we need to install yapf and for "deoplete-jedi", we need jedi

For that purpose, I propose you to perform this:

doas pip3 install yapf
doas pip3 install jedi

nvim config file

Here after the rest of the init.nvim config file I'm using with some explanations:

" Use deoplete.
let g:deoplete#enable_at_startup = 1
" use of UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" check parameters in ~/.config/yapf/style
let g:neoformat_python_autopep8 = {
        \ 'exe': 'yapf', 
        \ 'replace': 0, 
        \ 'stdin': 1, 
        \ }
" set background to dark
set background=dark
" change color of comments
hi Comment ctermfg=LightBlue
" change the background color of wrong spelled words
hi clear SpellBad
hi SpellBad cterm=underline
" tab size
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab smarttab autoindent
" ignore case for search
set incsearch ignorecase smartcase hlsearch
" ruler with command and mode
set ruler laststatus=2 showcmd showmode
set encoding=utf-8
" add line numbers
set number
" able to place the cursor based on the mouse position
set mouse=a

Lines starting by a double quote (") are comments in the init.nvim file's format.
Feel free to take only the element that fit your needs.

I will just provide more clarifications concerning "neoformat".

Configuration of neoformat and yapf

Neoformat is a tool that re-format your python code in order to match the standards (pep8, ...) in python programming.

The neoformat settings here above are just to inform which external tool I'm using for such formating exercise. In my case, I've selected yapf.

To tune yapf, you must read carefully the documentation provided by the command:

yapf --style-help

Please select the elements you needs and put them in the yapf configuration file: ~/.config/yapf/style

In my case, I do not want to respect the line's split at 80 characters, so my config file is this one:

# The column limit.

Please note, that, case by case, you can specify to yapf to NOT apply re-formating code by specifying "yapf: disable" in your code. All details available here

Simple gvim replacement: xnvim

On the GUI side, I'm using the Openbox; and I like to have different files edited in different windows (and in different desktops sometimes).

On top of Openbox, I'm using ranger as filemanager. So, I like that nvim will be directly open for text files, python scripts, shell scripts, ...

I propose you a simple gvim replacement, I've called it "xnvim".


/usr/X11R6/bin/xterm -geometry 90x35+10+10 -e /usr/local/bin/nvim -c "set title" -p -- "$@" &

Put this file in /usr/local/bin/xnvim, and make it executable: "chmod +x"

This simple script will open an xterm window (with the specified size) and execute nvim in it.

The specific parameters after the "nvim" commands tel that:

  • for "-p": in case several files are provided, nvim will open them in different tabs. You will be able to switch from tabs via the nvim commands: ":tabn" or ":tabp"
  • for "-c "set title": this means that the xterm window created will have, as title, the name of your file

Integration with ranger.

To ask ranger to trigger nvim for text files and script files, please adapt the 2 following lines in your "rifle.conf" file. This file is located in ~/.config/ranger.

mime ^text,  label editor = /usr/local/bin/xnvim "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = /usr/local/bin/xnvim "$@"

You can even select several files and request ranger to open it nvim will put them in different tabs.


With this quite simple setup of nvim I retrieve my vim (and gvim) habits.
Vim is moving forward and the neovim as build a community to take care of that.

35, 31
displayed: 9117

1. From walker on Sat Apr 4 13:54:37 2020

new neovim user here too. thanks a bunch for the useful guide! btw, I've to suppose git is already installed...

2. From Tadeusz on Sun Aug 20 03:10:50 2023

I notice in your neovim install that you're using the openbsd package manager as well as pip to install neovim e.g. does pkg_add neovim pip3.6 install neovim Just wondering why you need to install both.

3. From Vincent on Wed Aug 23 16:22:19 2023

Hello Tadeusz, I've installed jedi and yapf via pip because at that time openbsd package was on an older version. It was even maybe only python2.

What is the second letter of the word Moon?