Enable vim .nix syntax highlighting

How does one enable .nix code highlighting with vim?

nix edit nixpkgs.hello

works great with nano, but setting

export EDITOR=vi
nix edit nixpkgs.hello

I would of thought that a default install of vim on nixos would enable it, unless there is no standard plugin available?

There’s vim-nix. Vim stuff is documented in nixpkgs in doc/languages-frameworks/vim.section.md.

Thats certainly extensive documentation to install vim and it’s plugins, but i didn’t see anything about nix code highlighting? Unless it’s hidden away or a fell asleep while reading it?

Sorry, I was in a hurry when responding earlier. The plugin you want is called vim-nix. It’s packaged in nixpkgs and the code is on github here.

1 Like

Hey, thanks for your help, I now have vim nix code highlighting working great.

there may be a very very good reason vim nix code highlighting is not preinstalled on a nixos system, i guess it’s keep the system clean, and allow you to configure how you want to, but it’s highly likely at some point you will edit nix code on a nix system… I willing to put money on that.

1 Like

if your lucky/unlucky enough to be using a vim on osx then you will need.

git clone https://github.com/LnL7/vim-nix.git ~/.vim/pack/all/start/vim-nix
echo "syntax on" >> ~/.vimrc

to get syntax highlighting enabled. Just need autocompletion working next :-).