node.jsmacosvimneovimzshrc

Setting custom node version (path) for Neovim


TL;DR: I'd like to use node v14 for neovim only, and v8 for everything else. Suggestions?

Hello!

I have recently started using neovim for development purposes. I have installed several plugins, some of which require higher node versions than 8 - which is mandatory for my work environment. I used nvm, downloaded latest v14. Since nvm takes a ton of time to load up, I have added path in zshrc, which I simply changed from export PATH=../v8../bin to export PATH=../v14../bin. So far, so good. But my work repos throw errors, since they require node v8.

Now, I start up nvim on v14 in a session, then manually change path in zhsrc for work sessions to v8. This seems cumbersome to do every time. Is there a better way?


Solution

  • The following line can be added to your nvim/init.vim to prepend a directory DIR to your PATH when nvim is launched.

    let $PATH = 'DIR:' . $PATH
    

    Here's an example with the directory you specified.

    let $PATH = '../v14../bin:' . $PATH