Claiming back my Neovim responsiveness
I have been using Tmux and Neovim heavily for many years now; recently it has become very laggy and unresponsive. I love Vim, and I don’t want to just give up and switch to another editor, so I decided to spend some time to figure out what is wrong with this.
After digging around, I found out that I’m not alone! Many people have experienced similar issues, but interestingly, the solutions are varied, which drew my curiosity to find out more.
For my case, I can have Neovim running under Tmux quite well at the start; there are no noticeable issues I have. The problem usually starts after a couple of hours or if I’m working with quite a large file, which makes it difficult to trace down.
The suggested solutions I found mostly are around checking the Vim plugins and profiling the startup time. None of this detected the problem I have with my Vim.
Debugging
This is the hardest part, but here is what I tried:
Profiling Vim’s plugins
There are many Vim plugin profilers, but I just use this one https://github.com/hyiltiz/vim-plugins-profile. I tried to strip down some of my plugins, such as Deoplete, Nerdtree and some “experiment” plugins that I don’t really use for my everyday workflow.
Running Vim outside Tmux
This solved my issue, but I lost my favourite workflow of using vim-tmux-runner
to run test specs with vim-test
plugin on a Tmux split. This is probably my last option if I can’t find a way out.
Built-in Vim profiler
I got pretty much the same result as I got from vim-plugins-profile
when trying to run Vim’s built-in profiler:
Solutions over the internet
I tried to look for available solutions over the internet (Github issues, StackOverflow and blog posts) but I had no luck.
Some of them solved their issues by tweaking their iTerm scrollback
configuration https://arvid.io/2016/01/26/fixing-slow-vim-in-tmux-and-iterm2/.
Some others tweaked Tmux’s configuration (based on Github issue on Tmux project page https://github.com/tmux/tmux/issues/353):
- remove focus-events options
- set escape-time
The rest are solving their issue by combination of Vim configuration settings:
- 256 colorscheme
- lazyredraw
- cursorline/nocursorline
- ttyfast
- foldlevel/foldmethod
As I said earlier, the solutions are varied, but clearly, it’s all something related to screen redraw. On top of that either iTerm2, Tmux or Vim (Neovim) contributes to the issue, which is why no one really has a solution that works for everyone.
My solutions
After trying most of the solutions I mentioned above and still having no luck, it boils down into these paths:
1. Alacritty (https://github.com/jwilm/alacritty).
No doubt, Alacritty is an excellent project, and it’s blazing fast! The problem with this to me is that there are a couple of settings I have in Zsh that are incompatible, and I don’t want to spend more time to investigate further on this.
2. Neoterm (https://github.com/kassio/neoterm).
I really like to use Tmux to run specs from Vim and execute other commands asynchronously. Since I use Neovim instead of regular Vim, I have the advantage to be able to use Neovim’s terminal and use Neoterm to achieve similar behaviour I currently have with Tmux and Vim; the result is impressive!
Ditching Tmux
I have been using Tmux even before I switched from Vim to Neovim two years back. Tmux is definitely a great tool, it helps me to achieve a lot of fantastic stuff and support my Vim/Neovim workflow, but It’s time to say goodbye :)
Conclusion
All in all, iTerm, Tmux and Vim are great tools. In order to make them work perfectly, you need to pay attention to every single configuration and plugin you want to use. It is quite often that you need to make a trade-off decision in order to make sure each configuration doesn’t affect performance of any of those tools. My decision to use Neoterm is more to reduce additional tools and use the internal feature instead, which I expect will have fewer issues in the future.
Here is my Neoterm config in case you’re interested https://github.com/dferdian/dotfiles/blob/master/nvim/init.vim#L90-L98