1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-16 14:01:10 +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!"`
```nix
{
foo = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Some string";
default = null;
example = "Hello, world!";
};
}
```
@ -222,7 +224,7 @@ example = lib.literalExpression ''
{
foo = lib.nixvim.mkRaw "foo";
}
''
'';
```
Another example where `literalExpression` is beneficial is when your example includes multi-line strings.
@ -238,13 +240,13 @@ example = lib.literalExpression ''
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`.
E.g:
`````nix
````nix
example = lib.literalMD ''
This will render as normal text.
@ -253,8 +255,8 @@ example = lib.literalMD ''
```nix
This will render as nix code.
```
''
`````
'';
````
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:
```nix
{
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:
```nix
{
plugins.lsp.servers.nixd = {
enable = true;
settings = {
options.nixvim.expr = ''(builtins.getFlake "/path/to/flake").packages.${system}.neovimNixvim.options'';
};
settings.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:
```nix
{
# 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:
```nix
{
extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
name = "my-plugin";
src = pkgs.fetchFromGitHub {
@ -45,6 +47,7 @@ extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
hash = "<nix NAR hash>";
};
})];
}
```
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:
```nix
{
keymaps =
(builtins.map (key: {
inherit key;
@ -107,11 +111,13 @@ keymaps =
++ [
# Other keymaps...
];
}
```
This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to:
```nix
{
keymaps = [
{
key = "<key-1>";
@ -130,6 +136,7 @@ keymaps = [
}
# Other keymaps...
];
}
```
[`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
});
in
# configurations...
```
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:
```nix
plugins = {
grug-far = {
{
plugins.grug-far = {
enable = true;
lazyLoad = {
settings = {
cmd = "GrugFar";
};
};
};
lazyLoad.settings.cmd = "GrugFar";
};
}
```
Load on file type:
```nix
plugins = {
glow = {
{
plugins.glow = {
enable = true;
lazyLoad.settings.ft = "markdown";
};
}
```
Different load conditions:
```nix
{
plugins.toggleterm = {
enable = true;
lazyLoad = {
settings = {
lazyLoad.settings = {
cmd = "ToggleTerm";
keys = [
"<leader>tg"
@ -91,15 +88,15 @@ plugins.toggleterm = {
];
};
};
};
}
```
Load on keymap with dependency:
```nix
{
plugins.dap-ui = {
enable = true;
lazyLoad.settings = {
# We need to access nvim-dap in the after function.
before.__raw = ''
@ -121,6 +118,7 @@ Load on keymap with dependency:
];
};
};
}
```
### 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.
```nix
{
colorscheme = "catppuccin";
colorschemes.catppuccin = {
enable = true;
lazyLoad.enable = true;
};
}
```
To configure special integrations after `catppuccin` has been set up (while
still letting Nixvim manage lazy loading and the default `after`):
```nix
{
colorscheme = "catppuccin";
colorschemes.catppuccin = {
enable = true;
@ -161,4 +162,5 @@ plugins.bufferline = {
settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()";
lazyLoad.settings.lazy = true; # Lazy load manually
};
}
```