Improving Vim/Neovim Rendering Performance

Mon Apr 15, 2019
~400 Words

A work in progress, but if you’re experiencing slow rendering performance in vim or neovim (particularly in Ruby files) then here is a list of things to try for a hopefully smoother experience.

Disable relative line numbering

Relative line numbering is great for making quick jumps like 5j to jump down 5 lines, but every time you move up/down a line vim needs to redraw everything seemingly, so I’ve switched back to regular line numbering and use e.g. 123G to jump to where I want to go.

Use the previous regex engine

Also appears to be mostly an issue with vim-ruby, but the newer NFA-based regex engine in vim appears to cause massive slowdowns in Ruby files, though perhaps only on older CPUs.

Experiment with adding set regexpengine=1 to use the previous regex engine which appears to be lighter on the CPU.

For Ruby: install the latest vim-ruby

Try installing vim-ruby explicitly as a plugin to get the very latest version—it’s bundled with vim but the version is likely to lag slightly behind the releases of vim-ruby itself.

Eliminate slow plugins

Disable as many plugins as you can and see if that improves the situation, re-enable until you find the culprit then evaluate whether there is a setting available to tune its behaviour or whether it would be worth removing.

If you have a status line plugin then I would start there as they have a tendency to be on the expensive side in terms of rendering.

Experiment with vim/neovim rendering settings

Experiment with set ttyfast and set lazyredraw.

Reduce escape-time if using Tmux

If you use tmux, experiment with reducing the escape-time setting, e.g. set -g escape-time 10—this will not affect scrolling/rendering but the default value adds to the latency of getting out of insert mode and so to the overall experience in vim.

Switch terminal emulator

If you’re using terminal vim/neovim, try Alacritty—if your machine has a reasonable GPU you should see a decent reduction in latency, though you many need to invest in configuring it work well with your existing setup

If Alacritty is not an option then try, which on OSX appears to provide better performance than e.g. iTerm2

Did you find this post useful? If you would like help with anything then you can contact me any time via Twitter.