jorgebucaran / nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
https://git.io/nvm.fish
MIT License
2.06k stars 69 forks source link

nvim + nvm configuration #197

Closed Lilja closed 1 year ago

Lilja commented 1 year ago

Hi!

I'm using neovim heavily and have thought how to make best use of both worlds.

One problem that I'm running into constantly is that I have two node versions on my machine, v18 and v16. On node 18 I have my LSPs and the v16 is mostly for running a specific project. Since most of my stuff for my developer environment is for v18, I get lots of errors when I accidentally open neovim with it. I usually have to quit vim, do nvm use v18.8.8 and then re-open vim.

This is a bit tedious and I would've think that there must be people that have the same problem.

In neovim, there is a option that you define a global variable called g:node_host_prog. Which I guess you could do nvm use v18.8.0 && which node and paste that into there. But this won't work well with other machines as you often tend to share dotfiles. Would it be feasible to add a command to get the path of a particular node managed by nvm? For example, in nvim I could define: let g:node_host_prog=system("nvim get-path lts/gallium")

Let me know if I can clarify anything or if I'm missing something.

jorgebucaran commented 1 year ago

Try using $nvm_data.

If you want to get the path of the current Node:

$nvm_data/(nvm current)

If you want to get the path of a specific Node:

$nvm_data/v18.8.8
Lilja commented 1 year ago

I don't have that environmental variable in my env. I was on 2.2.6 and updated to 2.2.11, I did nvm use v16.16.0 but no nvm_data:

lilja in ~/dotfiles on master λ nvm use v16.15.0
Now using Node v16.15.0 (npm 8.5.5) ~/.local/share/nvm/v16.15.0/bin/node
ilja in ~/dotfiles on master λ  env | grep nvm
nvm_current_version=v16.15.0
jorgebucaran commented 1 year ago

You must have that variable in your environment as it's set both during installation:

https://github.com/jorgebucaran/nvm.fish/blob/9db8eaf6e3064a962bca398edd42162f65058ae8/conf.d/nvm.fish#L1-L4

and update:

https://github.com/jorgebucaran/nvm.fish/blob/9db8eaf6e3064a962bca398edd42162f65058ae8/conf.d/nvm.fish#L11-L14

Lilja commented 1 year ago

I did echo $nvm_data, and it worked. Surprised that env | grep nvm doesn't work for it.

Nevertheless, I'll try that out for now and experiment.

Thanks for your help and your great project!

jorgebucaran commented 1 year ago

$nvm_data is not exported, that's why it's not available to env, but you can query Fish variables using just set.

$ set | string match nvm\*
nvm_current_version v19.0.1
nvm_data /Users/jb/.local/share/nvm
nvm_default_version latest
nvm_mirror https://nodejs.org/dist