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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s