1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-17 06:21:13 +01:00

docs: format nix examples in documentation

This commit is contained in:
Zexin Yuan 2025-12-12 18:53:31 +08:00 committed by Gaétan Lepage
parent 993a8b4eb0
commit d52007581e
6 changed files with 133 additions and 120 deletions

View file

@ -198,11 +198,13 @@ For example this option will render something like:
> **Example**: `"Hello, world!"` > **Example**: `"Hello, world!"`
```nix ```nix
{
foo = lib.mkOption { foo = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.nullOr lib.types.str;
description = "Some string"; description = "Some string";
default = null; default = null;
example = "Hello, world!"; example = "Hello, world!";
};
} }
``` ```
@ -222,7 +224,7 @@ example = lib.literalExpression ''
{ {
foo = lib.nixvim.mkRaw "foo"; foo = lib.nixvim.mkRaw "foo";
} }
'' '';
``` ```
Another example where `literalExpression` is beneficial is when your example includes multi-line strings. Another example where `literalExpression` is beneficial is when your example includes multi-line strings.
@ -238,13 +240,13 @@ example = lib.literalExpression ''
several lines! several lines!
'''; ''';
} }
'' '';
``` ```
On very rare occasions, you may wish to include some non-code text within your example. This can be done by wrapping a markdown string with `lib.literalMD`. On very rare occasions, you may wish to include some non-code text within your example. This can be done by wrapping a markdown string with `lib.literalMD`.
E.g: E.g:
`````nix ````nix
example = lib.literalMD '' example = lib.literalMD ''
This will render as normal text. This will render as normal text.
@ -253,8 +255,8 @@ example = lib.literalMD ''
```nix ```nix
This will render as nix code. This will render as nix code.
``` ```
'' '';
````` ````
See also: [Writing NixOS Modules: Option Declarations](https://nixos.org/manual/nixos/unstable/#sec-option-declarations) (NixOS Manual). See also: [Writing NixOS Modules: Option Declarations](https://nixos.org/manual/nixos/unstable/#sec-option-declarations) (NixOS Manual).

View file

@ -26,6 +26,7 @@ in
``` ```
The extended `lib` is also accessible in the `lib` module argument in the `programs.nixvim` submodule: The extended `lib` is also accessible in the `lib` module argument in the `programs.nixvim` submodule:
```nix ```nix
{ {
programs.nixvim = programs.nixvim =

View file

@ -61,10 +61,10 @@ Given a Nixvim derivation it is possible to access the module options using `<de
This can be useful to configure `nixd` for example: This can be useful to configure `nixd` for example:
```nix ```nix
{
plugins.lsp.servers.nixd = { plugins.lsp.servers.nixd = {
enable = true; enable = true;
settings = { settings.options.nixvim.expr = ''(builtins.getFlake "/path/to/flake").packages.${system}.neovimNixvim.options'';
options.nixvim.expr = ''(builtins.getFlake "/path/to/flake").packages.${system}.neovimNixvim.options'';
};
}; };
}
``` ```

View file

@ -19,6 +19,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
``` ```
Import it into your Nixvim configuration and configure it: Import it into your Nixvim configuration and configure it:
```nix ```nix
{ {
# Remove this `programs.nixvim` wrapper for standalone configurations # Remove this `programs.nixvim` wrapper for standalone configurations
@ -36,6 +37,7 @@ Import it into your Nixvim configuration and configure it:
This is straightforward too, you can add the following to `extraPlugins` for a plugin hosted on GitHub: This is straightforward too, you can add the following to `extraPlugins` for a plugin hosted on GitHub:
```nix ```nix
{
extraPlugins = [(pkgs.vimUtils.buildVimPlugin { extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
name = "my-plugin"; name = "my-plugin";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
@ -45,6 +47,7 @@ extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
hash = "<nix NAR hash>"; hash = "<nix NAR hash>";
}; };
})]; })];
}
``` ```
The [nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#managing-plugins-with-vim-packages) has more information on this. The [nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#managing-plugins-with-vim-packages) has more information on this.
@ -98,6 +101,7 @@ This is so that Nixvim is built against the same nixpkgs revision we're using in
You could use the builtin [`map`] function (or similar) to do something like this: You could use the builtin [`map`] function (or similar) to do something like this:
```nix ```nix
{
keymaps = keymaps =
(builtins.map (key: { (builtins.map (key: {
inherit key; inherit key;
@ -107,11 +111,13 @@ keymaps =
++ [ ++ [
# Other keymaps... # Other keymaps...
]; ];
}
``` ```
This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to: This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to:
```nix ```nix
{
keymaps = [ keymaps = [
{ {
key = "<key-1>"; key = "<key-1>";
@ -130,6 +136,7 @@ keymaps = [
} }
# Other keymaps... # Other keymaps...
]; ];
}
``` ```
[`map`]: https://nixos.org/manual/nix/stable/language/builtins#builtins-map [`map`]: https://nixos.org/manual/nix/stable/language/builtins#builtins-map

View file

@ -27,6 +27,7 @@ let
# When using a different channel you can use `ref = "nixos-<version>"` to set it here # When using a different channel you can use `ref = "nixos-<version>"` to set it here
}); });
in in
# configurations...
``` ```
When using flakes you can simply add `nixvim` to the inputs: When using flakes you can simply add `nixvim` to the inputs:

View file

@ -55,35 +55,32 @@ is done through the `lazyLoad.settings` option.
Load on command: Load on command:
```nix ```nix
plugins = { {
grug-far = { plugins.grug-far = {
enable = true; enable = true;
lazyLoad = { lazyLoad.settings.cmd = "GrugFar";
settings = {
cmd = "GrugFar";
};
};
};
}; };
}
``` ```
Load on file type: Load on file type:
```nix ```nix
plugins = { {
glow = { plugins.glow = {
enable = true; enable = true;
lazyLoad.settings.ft = "markdown"; lazyLoad.settings.ft = "markdown";
}; };
}
``` ```
Different load conditions: Different load conditions:
```nix ```nix
{
plugins.toggleterm = { plugins.toggleterm = {
enable = true; enable = true;
lazyLoad = { lazyLoad.settings = {
settings = {
cmd = "ToggleTerm"; cmd = "ToggleTerm";
keys = [ keys = [
"<leader>tg" "<leader>tg"
@ -91,15 +88,15 @@ plugins.toggleterm = {
]; ];
}; };
}; };
}; }
``` ```
Load on keymap with dependency: Load on keymap with dependency:
```nix ```nix
{
plugins.dap-ui = { plugins.dap-ui = {
enable = true; enable = true;
lazyLoad.settings = { lazyLoad.settings = {
# We need to access nvim-dap in the after function. # We need to access nvim-dap in the after function.
before.__raw = '' before.__raw = ''
@ -121,6 +118,7 @@ Load on keymap with dependency:
]; ];
}; };
}; };
}
``` ```
### Colorschemes ### Colorschemes
@ -130,17 +128,20 @@ set up the `colorscheme` trigger to the name of the `colorscheme` so that it is
lazy loaded when the `colorscheme` is requested. lazy loaded when the `colorscheme` is requested.
```nix ```nix
{
colorscheme = "catppuccin"; colorscheme = "catppuccin";
colorschemes.catppuccin = { colorschemes.catppuccin = {
enable = true; enable = true;
lazyLoad.enable = true; lazyLoad.enable = true;
}; };
}
``` ```
To configure special integrations after `catppuccin` has been set up (while To configure special integrations after `catppuccin` has been set up (while
still letting Nixvim manage lazy loading and the default `after`): still letting Nixvim manage lazy loading and the default `after`):
```nix ```nix
{
colorscheme = "catppuccin"; colorscheme = "catppuccin";
colorschemes.catppuccin = { colorschemes.catppuccin = {
enable = true; enable = true;
@ -161,4 +162,5 @@ plugins.bufferline = {
settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()"; settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()";
lazyLoad.settings.lazy = true; # Lazy load manually lazyLoad.settings.lazy = true; # Lazy load manually
}; };
}
``` ```