Editor Modes for Nix Files: Difference between revisions

From NixOS Wiki
imported>Hasit
Add zed-nix link
Klinger (talk | contribs)
m typo
Line 2: Line 2:


== Language servers ==
== Language servers ==
Most popular editors have support for the l[https://microsoft.github.io/language-server-protocol language server protocol], the following language servers can be used to provide features like completions and go-to-definition.
Most popular editors have support for the [https://microsoft.github.io/language-server-protocol language server protocol], the following language servers can be used to provide features like completions and go-to-definition.
* [https://github.com/oxalica/nil nil]
* [https://github.com/oxalica/nil nil]
* [https://github.com/nix-community/rnix-lsp rnix-lsp]
* [https://github.com/nix-community/rnix-lsp rnix-lsp]

Revision as of 20:05, 18 April 2024

Nix language has decent syntax highlighting (SH) support among popular code editors, but refactoring/autocomplete is still rare. Below is a list of editor modes for Nix syntax.

Language servers

Most popular editors have support for the language server protocol, the following language servers can be used to provide features like completions and go-to-definition.

Emacs

Vim

vim-addon-nix

This plugin supports syntax highlighting and simple syntax and undeclared variable checking.

Usage with VAM package manager:

{ # /etc/nixos/configuration.nix
  environment.systemPackages = [
    (pkgs.vim_configurable.customize {
      name = "vim";
      vimrcConfig.vam.pluginDictionaries = [
        # vim-nix handles indentation better but does not perform sanity
        { names = [ "vim-addon-nix" ]; ft_regex = "^nix\$"; }
      ];
    })
  ];
}

vim-nix

vim-nix *only* supports syntax-highighting.

Usage with vim package manager:

{ # /etc/nixos/configuration.nix
  environment.systemPackages = [
    (pkgs.vim_configurable.customize {
      name = "vim";
      vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
        start = [ vim-nix ]; # load plugin on startup
      };
    })
  ];
}

Neovim

In addition to the Vim plugins listed above, nvim-treesitter also has support for nix.

{
  programs.neovim = {
    configure = {
      packages.all.start = with pkgs.vimPlugins; [
        (nvim-treesitter.withPlugins (ps: [ ps.nix ]))
        # or
        nvim-treesitter.withAllGrammars # to install all grammars (including nix)
      ];
    };
  };
}

IntelliJ IDEA

Eclipse

Sublime Text

Atom

Visual Studio Code

Howl

Far2l

nano

Codemirror

Zed

Relevant pages