Retour au classement

nix-community/nixvim

Nixnix-community.github.io/nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]

neovimnixnixosnixos-modulevim
Croissance des étoiles
Étoiles
2.9k
Forks
397
Croissance hebdomadaire
Issues
117
1k2k
mars 2021déc. 2022oct. 2024juil. 2026
README

Documentation | Chat

Nixvim - A Neovim configuration system for nix

What is it?

Nixvim is a Neovim distribution built around Nix modules. It is distributed as a Nix flake, and configured through Nix, all while leaving room for your plugins and your vimrc.

What does it look like?

Here is a simple configuration that uses catppuccin as the colorscheme and uses the lualine plugin:

{
  programs.nixvim = {
    enable = true;

    colorschemes.catppuccin.enable = true;
    plugins.lualine.enable = true;
  };
}

When we do this, lualine will be set up to a sensible default, and will use catppuccin as the colorscheme, no extra configuration required!

Check out this list of real world Nixvim configs!

How does it work?

When you build the module (probably using Home Manager), it will install all your plugins and generate a lua config for Neovim with all the options specified. Because it uses lua, this ensures that your configuration will load as fast as possible.

Since everything is disabled by default, it will be as snappy as you want it to be.

Plugin settings

Most plugins have a settings option, which accepts any nix attribute set and translate it into a lua table. This is then passed to the plugin's setup function. In practice this means if a plugin has a settings option, any plugin option can be configured, even if we don't explicitly have a corresponding nix option.

Raw lua

If you just want to add additional lines of lua to your init.lua, you can use extraConfigLua, extraConfigLuaPre, and extraConfigLuaPost.

If you want to assign lua code to an option that'd normally accept another type (string, int, etc), you can use Nixvim's "raw type", { __raw = "lua code"; }.

Example

This nix code:

{
  some_option.__raw = "function() print('hello, world!') end";
}

Will produce the following lua:

{
  ['some_option'] = function() print('hello, world!') end,
}

Support/Questions

If you have any question, please use the discussions page! Alternatively, join the Matrix channel at #nixvim:matrix.org!

Installation

[!WARNING] Nixvim needs to be installed with a compatible nixpkgs version. This means that the main branch of Nixvim requires to be installed with nixpkgs-unstable.

If you want to use Nixvim with nixpkgs 26.05 you should use the nixos-26.05 branch.

For more detail, see the Installation section of our documentation.

Without flakes

Nixvim now ships with flake-compat, which makes it usable from any system.

To install it, edit your Home Manager, NixOS or nix-darwin configuration:

{ pkgs, lib, ... }:
let
  nixvim = import (builtins.fetchGit {
    url = "https://github.com/nix-community/nixvim";
    # If you are not running an unstable channel of nixpkgs, select the corresponding branch of Nixvim.
    # ref = "nixos-26.05";
  });
in
{
  imports = [
    # For Home Manager
    nixvim.homeModules.nixvim
    # For NixOS
    nixvim.nixosModules.nixvim
    # For nix-darwin
    nixvim.nixDarwinModules.nixvim
  ];

  programs.nixvim.enable = true;
}
Using flakes

This is the recommended method if you are already using flakes to manage your system. To enable flakes, add this to /etc/nixos/configuration.nix

{ pkgs, lib, ... }:
{
  nix = {
    settings.experimental-features = [ "nix-command" "flakes" ];
  };
}

Now, you need to import the module. If your system is already configured using flakes, just add the nixvim input:

{
  # ...
  inputs.nixvim = {
    url = "github:nix-community/nixvim";
    # If you are not running an unstable channel of nixpkgs, select the corresponding branch of Nixvim.
    # url = "github:nix-community/nixvim/nixos-26.05";
  };
}

Nixvim is tested against its own Nixpkgs revision. We recommend not overriding its nixpkgs input with follows; see the installation guide for details.

You can now access the module using inputs.nixvim.homeModules.nixvim, for a Home Manager installation, inputs.nixvim.nixosModules.nixvim, for NixOS, and inputs.nixvim.nixDarwinModules.nixvim for nix-darwin.

Usage

Nixvim can be used in four ways: through the Home Manager, nix-darwin, NixOS modules, and standalone through the makeNixvim function. To use the modules, just import the nixvim.homeModules.nixvim, nixvim.nixDarwinModules.nixvim, and nixvim.nixosModules.nixvim modules, depending on which system you're using.

For more detail, see the Usage section of our documentation.

Standalone Usage

Nixvim can also be used separately from NixOS, Home Manager, etc. To use Nixvim standalone, evaluate a Nixvim configuration and use its package output:

let
  nixvim = import (builtins.fetchTarball {
    # ...
  });
  configuration = nixvim.lib.evalNixvim {
    system = builtins.currentSystem;

    modules = [
      {
        colorschemes.gruvbox.enable = true;
      }
    ];
  };
in
configuration.config.build.package

The configuration also exposes a test derivation through configuration.config.build.test, which can be used from checks.

To get started with a standalone configuration, you can use the template by running the following command in an empty directory (recommended):

nix flake init --template github:nix-community/nixvim

Alternatively, you can create a minimal flake:

Minimal flake configuration
{
  description = "A very basic flake";

  inputs = {
    nixpkgs.follows = "nixvim/nixpkgs";
    nixvim.url = "github:nix-community/nixvim";
  };

  outputs =
    { nixpkgs, nixvim, ... }:
    let
      systems = [
        "x86_64-linux"
        "aarch64-linux"
        "aarch64-darwin"
      ];

      forAllSystems = nixpkgs.lib.genAttrs systems;
    in
    {
      packages = forAllSystems (
        system:
        let
          configuration = nixvim.lib.evalNixvim {
            inherit system;

            modules = [
              {
                colorschemes.gruvbox.enable = true;
              }
            ];
          };
        in
        {
          default = configuration.config.build.package;
        }
      );
    };
}

You can then run Neovim using nix run .# -- <file>. This can be useful for testing configuration changes.

For more information, see the Standalone Usage docs.

Documentation

Documentation is available on this project's GitHub Pages page: https://nix-community.github.io/nixvim

The stable documentation is also available at https://nix-community.github.io/nixvim/26.05.

If the option enableMan is set to true (by default it is), man pages will also be installed containing the same information, they can be viewed with man nixvim.

Plugins

After you have installed Nixvim, you will no doubt want to enable some plugins. Plugins are based on a modules system, similarly to NixOS and Home Manager.

So, to enable some supported plugin, all you have to do is enable its module:

{
  programs.nixvim = {
    plugins.lightline.enable = true;
  };
}

Of course, if that was everything, there wouldn't be much point to Nixvim, you'd just use a regular plugin manager. All options for supported plugins are exposed as options of that module. For now, there is no documentation yet, but there are detailed explanations in the source code. Detailed documentation for every module is planned.

Not all plugins will have modules, so you might still want to fetch some. This is not a problem, just use the extraPlugins option:

{
  programs.nixvim = {
    extraPlugins = with pkgs.vimPlugins; [
      vim-nix
    ];
  };
}

However, if you find yourself doing this a lot, please consider contributing or requesting a module!

Colorschemes

Colorschemes are provided within a different scope:

{
  programs.nixvim = {
    # Enable gruvbox
    colorschemes.gruvbox.enable = true;
  };
}

Just like with normal plugins, extra colorscheme options are provided as part of its module.

If your colorscheme isn't provided as a module, install it using extraPlugins and set it using the colorscheme option:

{
  programs.nixvim = {
    extraPlugins = [ pkgs.vimPlugins.gruvbox ];
    colorscheme = "gruvbox";
  };
}

All Nixvim supported plugins will, by default, use the main colorscheme you set, though this can be overridden on a per-plugin basis.

Options

Neovim has a lot of configuration options. You can find a list of them by doing :h option-list from within Neovim.

All of these are configurable from within Nixvim. All you have to do is set the opts attribute:

{
  programs.nixvim = {
    opts = {
      number = true;         # Show line numbers
      relativenumber = true; # Show relative line numbers

      shiftwidth = 2;        # Tab width should be 2
    };
  };
}

Please note that to, for example, disable numbers you would not set opts.nonumber to true, you'd set opts.number to false.

Key mappings

It is fully possible to define key mappings from within Nixvim. This is done using the keymaps attribute:

{
  programs.nixvim = {
    keymaps = [
      {
        key = ";";
        action = ":";
      }
      {
        mode = "n";
        key = "<leader>m";
        options.silent = true;
        action = "<cmd>!make<CR>";
      }
    ];
  };
}

This is equivalent to this vimscript:

noremap ; :
nnoremap <leader>m <silent> <cmd>make<CR>

This table describes all modes for the keymaps option. You can provide several modes to a single mapping by using a list of strings.

Mode Norm Ins Cmd Vis Sel Opr Term Lang Description
"" yes - - yes yes yes - - Equivalent to :map
"n" yes - - - - - - - Normal mode
"!" - yes yes - - - - - Insert and command-line mode
"i" - yes - - - - - - Insert mode
"c" - - yes - - - - - Command-line mode
"v" - - - yes yes - - - Visual and Select mode
"x" - - - yes - - - - Visual mode only, without select
"s" - - - - yes - - - Select mode
"o" - - - - - yes - - Operator-pending mode
"t" - - - - - - yes - Terminal mode
"l" - yes yes - - - - yes Insert, command-line and lang-arg mode
"!a" - abr abr - - - - - Abbreviation in insert and command-line mode
"ia" - abr - - - - - - Abbreviation in insert mode
"ca" - - abr - - - - - Abbreviation in command-line mode

Each keymap can specify the following settings in the options attrs.

Nixvim Default VimScript
silent false <silent>
nowait false <silent>
script false <script>
expr false <expr>
unique false <unique>
noremap true Use the 'noremap' variant of the mapping
remap false Make the mapping recursive (inverses noremap)
desc "" A description of this keymap

Globals

Sometimes you might want to define a global variable, for example to set the leader key. This is easy with the globals attribute:

{
  programs.nixvim = {
    globals.mapleader = ","; # Sets the leader key to comma
  };
}

Additional config

Sometimes Nixvim won't be able to provide for all your customization needs. In these cases, the extraConfigVim and extraConfigLua options are provided:

{
  programs.nixvim = {
    extraConfigLua = ''
      -- Print a little welcome message when Neovim is opened!
      print("Hello world!")
    '';
  };
}

If you feel like what you are doing manually should be supported in Nixvim, please open an issue.

Contributing

See CONTRIBUTING.md

Dépôts similaires
neovim/neovim

Vim-fork focused on extensibility and usability

Vim ScriptOtherneovimc
neovim.io
101.3k7k
junegunn/fzf

:cherry_blossom: A command-line fuzzy finder

GoGo ModulesMIT Licensefzfgo
junegunn.github.io/fzf/
81.9k2.8k
sxyazi/yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.

Rustcrates.ioMIT Licenseasyncioconcurrency
yazi-rs.github.io
40.6k945
NvChad/NvChad

Blazing fast Neovim framework providing solid defaults and a beautiful UI, enhancing your neovim experience.

LuaGNU General Public License v3.0nvimneovim
nvchad.com
28.4k2.2k
LazyVim/LazyVim

Neovim config for the lazy

LuaApache License 2.0neovimneovim-conf
lazyvim.github.io
27k1.8k
folke/lazy.nvim

💤 A modern plugin manager for Neovim

LuaApache License 2.0neovimneovim-plugin
lazy.folke.io
21.3k585
rockerBOO/awesome-neovim

Collections of awesome neovim plugins.

ShellCreative Commons Zero v1.0 Universalnvim-luaneovim
21.2k1k
SpaceVim/SpaceVim

A modular configuration of Vim and Neovim

Vim Scriptneovimspacevim
spacevim.org
20.4k1.4k
wsdjeg/SpaceVim

A modular configuration of Vim and Neovim

Vim ScriptGNU General Public License v3.0neovimspacevim
spacevim.org
20.2k1.4k
nvim-telescope/telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.

LuaMIT Licenseneovimlua
19.6k956
LunarVim/LunarVim

🌙 LunarVim is an IDE layer for Neovim. Completely free and community driven.

LuaGNU General Public License v3.0neovimvim
lunarvim.org
19.3k1.5k
mhinz/vim-galore

:mortar_board: All things Vim!

Vim ScriptCreative Commons Attribution Share Alike 4.0 Internationalvimguide
17.9k631