Diagnosing Outrageously Slow NeoVIM Editor

2 minute read

Published:

I will be starting my PhD soon. As I’ll have to write a lot during that long degree, I thought it’s time to develop a proper/customized document processing system. I have a few days of free time before the start start of the semester. It occurred to me that it might be a good time to get more comfortable with LaTeX since I plan to use it a lot. Even thought I have made a lot of documents with latex in the past, I still think my latex skills are pretty limited. The reason for that is, I’ve mostly worked with pre-existing templates from the internet. Never developed one. I also find myself googling a lot more than I am comfortable admitting. This can distract you pretty fast, especially when a deadline is tight.

I was working on setting up a lightweight LaTeX writing workflow. VIM is my all-time favorite text editor. I use VIM keybindings wherever I can. Even when I use a bulkier text editor (VScode) I use Vim extensions to imitate the experience. Since I am on a Windows machine now (because Linux audio drivers don’t work in my current Huawei B430 laptop), I wanted to set it up with WSL - windows subsystem for Linux and VIM. I could’ve gone with the MiKTeX and IDE route. But that doesn’t seem as enticing as typing-in-a-terminal, does it? Here’s a medium article link on how to set up LaTeX on a windows machine with WSL and neovim.

The primary selling point of a lightweight text editor is that - it is blazing fast to start. But with my VIM configuration file and VimTeX plugin, the startup time for the editor was unacceptable. It took around 3-4 seconds to load the editor. So I had to investigate this issue, find out the source of this delay.

A good way to do this is starting neovim with –startuptime flag. neovim --startuptime output.log

I did it twice, once with my configuration file (where the issue was) and another time without any configuration. Upon inspecting the logfile, I found that neovim is sourcing a file called clipboard.vim. Here’s a snippet of the log file. The clipboard.vim file takes 3218 miliseconds (3.2 seconds) to load!

063.805  000.006: editing files in windows
063.970  000.165: VimEnter autocommands
063.974  000.004: UIEnter autocommands
3283.404  3218.449  3218.449: sourcing /snap/nvim/2819/usr/share/nvim/runtime/autoload/provider/clipboard.vim
3283.499  001.076: before starting main loop
3284.077  000.578: first screen update
3284.083  000.006: --- NVIM STARTED ---

The culprit was immediately evident. I had a line in my configuration file related to clipboard.

set clipboard=unnamedplus

This sentence makes it so that the VIM copy register is synchronized with operating systems clipboard. If you are interested in understanding, this video does a pretty good job of explaining.

Anyhow, I’ve removed this line from the config, and everything is back on track for now.