Slow Vim? Check your ~/.zshenv

This is probably a “duh” tip, but here goes: don’t put heavy loading code in ~/.zshenv because this code will be processed in every system call inside another program like Vim, making the program seem slow.

Like every single programmer I maintain a repo of my dotfiles that I constantly tinker with. At some point I was reorganizing my ~/.zshrc and I moved some things into ~/.zshenv according to my (weak) understanding of how these things should be separated, mainly based on the advice of this Stack Overflow page.

So I gathered that you should put important environment variables there, but as you can see I also decided that this is where you should put the initialization code for rbenv, direnv, etc.

Don’t do this. I thought that Vim (actually I use Neovim these days) had become horribly slow and was inclined to blame this on individual plugins or just Vimscript in general. As soon as I moved the offending code out of ~/.zshenv into ~/.zshrc my Vim sped up dramatically.