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:
parent
993a8b4eb0
commit
d52007581e
6 changed files with 133 additions and 120 deletions
|
|
@ -198,11 +198,13 @@ For example this option will render something like:
|
||||||
> **Example**: `"Hello, world!"`
|
> **Example**: `"Hello, world!"`
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
foo = lib.mkOption {
|
{
|
||||||
type = lib.types.nullOr lib.types.str;
|
foo = lib.mkOption {
|
||||||
description = "Some string";
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
description = "Some string";
|
||||||
example = "Hello, world!";
|
default = null;
|
||||||
|
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).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 =
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ This function is recursive, meaning that it can be applied an arbitrary number o
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{makeNixvim}: let
|
{makeNixvim}: let
|
||||||
first = makeNixvim { extraConfigLua = "-- first stage"; };
|
first = makeNixvim { extraConfigLua = "-- first stage"; };
|
||||||
second = first.extend {extraConfigLua = "-- second stage";};
|
second = first.extend {extraConfigLua = "-- second stage";};
|
||||||
third = second.extend {extraConfigLua = "-- third stage";};
|
third = second.extend {extraConfigLua = "-- third stage";};
|
||||||
in
|
in
|
||||||
third
|
third
|
||||||
```
|
```
|
||||||
|
|
||||||
This will generate a `init.lua` that will contain the comments from each stages:
|
This will generate a `init.lua` that will contain the comments from each stages:
|
||||||
|
|
@ -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'';
|
};
|
||||||
};
|
}
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -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,7 +37,8 @@ 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 {
|
||||||
owner = "<owner>";
|
owner = "<owner>";
|
||||||
|
|
@ -44,7 +46,8 @@ extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
|
||||||
rev = "<commit hash>";
|
rev = "<commit hash>";
|
||||||
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,38 +101,42 @@ 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 =
|
{
|
||||||
(builtins.map (key: {
|
keymaps =
|
||||||
inherit key;
|
(builtins.map (key: {
|
||||||
action = "<some-action>";
|
inherit key;
|
||||||
options.desc = "My cool keymapping";
|
action = "<some-action>";
|
||||||
}) ["<key-1>" "<key-2>" "<key-3>"])
|
options.desc = "My cool keymapping";
|
||||||
++ [
|
}) ["<key-1>" "<key-2>" "<key-3>"])
|
||||||
# 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>";
|
{
|
||||||
action = "<some-action>";
|
key = "<key-1>";
|
||||||
options.desc = "My cool keymapping";
|
action = "<some-action>";
|
||||||
}
|
options.desc = "My cool keymapping";
|
||||||
{
|
}
|
||||||
key = "<key-2>";
|
{
|
||||||
action = "<some-action>";
|
key = "<key-2>";
|
||||||
options.desc = "My cool keymapping";
|
action = "<some-action>";
|
||||||
}
|
options.desc = "My cool keymapping";
|
||||||
{
|
}
|
||||||
key = "<key-3>";
|
{
|
||||||
action = "<some-action>";
|
key = "<key-3>";
|
||||||
options.desc = "My cool keymapping";
|
action = "<some-action>";
|
||||||
}
|
options.desc = "My cool keymapping";
|
||||||
# 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
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,23 @@ Nixvim is also available for nix flakes, or directly through an import.
|
||||||
For a direct import you can add Nixvim to your configuration as follows:
|
For a direct import you can add Nixvim to your configuration as follows:
|
||||||
```nix
|
```nix
|
||||||
let
|
let
|
||||||
nixvim = import (builtins.fetchGit {
|
nixvim = import (builtins.fetchGit {
|
||||||
url = "https://github.com/nix-community/nixvim";
|
url = "https://github.com/nix-community/nixvim";
|
||||||
# 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:
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
inputs.nixvim = {
|
inputs.nixvim = {
|
||||||
url = "github:nix-community/nixvim";
|
url = "github:nix-community/nixvim";
|
||||||
# If using a stable channel you can use `url = "github:nix-community/nixvim/nixos-<version>"`
|
# If using a stable channel you can use `url = "github:nix-community/nixvim/nixos-<version>"`
|
||||||
};
|
};
|
||||||
|
|
||||||
# outputs...
|
# outputs...
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -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 = {
|
{
|
||||||
enable = true;
|
plugins.toggleterm = {
|
||||||
lazyLoad = {
|
enable = true;
|
||||||
settings = {
|
lazyLoad.settings = {
|
||||||
cmd = "ToggleTerm";
|
cmd = "ToggleTerm";
|
||||||
keys = [
|
keys = [
|
||||||
"<leader>tg"
|
"<leader>tg"
|
||||||
|
|
@ -91,36 +88,37 @@ plugins.toggleterm = {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Load on keymap with dependency:
|
Load on keymap with dependency:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
plugins.dap-ui = {
|
{
|
||||||
enable = true;
|
plugins.dap-ui = {
|
||||||
|
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 = ''
|
||||||
function()
|
function()
|
||||||
require('lz.n').trigger_load('nvim-dap')
|
require('lz.n').trigger_load('nvim-dap')
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
keys = [
|
keys = [
|
||||||
{
|
{
|
||||||
__unkeyed-1 = "<leader>du";
|
__unkeyed-1 = "<leader>du";
|
||||||
__unkeyed-2.__raw = ''
|
__unkeyed-2.__raw = ''
|
||||||
function()
|
function()
|
||||||
require('dap.ext.vscode').load_launchjs(nil, {})
|
require('dap.ext.vscode').load_launchjs(nil, {})
|
||||||
require("dapui").toggle()
|
require("dapui").toggle()
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
desc = "Toggle Debugger UI";
|
desc = "Toggle Debugger UI";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Colorschemes
|
### Colorschemes
|
||||||
|
|
@ -130,35 +128,39 @@ 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";
|
{
|
||||||
colorschemes.catppuccin = {
|
colorscheme = "catppuccin";
|
||||||
enable = true;
|
colorschemes.catppuccin = {
|
||||||
lazyLoad.enable = true;
|
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";
|
{
|
||||||
colorschemes.catppuccin = {
|
colorscheme = "catppuccin";
|
||||||
enable = true;
|
colorschemes.catppuccin = {
|
||||||
lazyLoad.enable = true;
|
enable = true;
|
||||||
|
lazyLoad.enable = true;
|
||||||
# This code runs after catppuccin is setup,
|
|
||||||
# regardless of whether it was lazy-loaded or not.
|
# This code runs after catppuccin is setup,
|
||||||
luaConfig.post = ''
|
# regardless of whether it was lazy-loaded or not.
|
||||||
-- At this point catppuccin is configured, so we can safely
|
luaConfig.post = ''
|
||||||
-- derive bufferline highlights or similar settings from it.
|
-- At this point catppuccin is configured, so we can safely
|
||||||
require('lz.n').trigger_load("bufferline.nvim")
|
-- derive bufferline highlights or similar settings from it.
|
||||||
'';
|
require('lz.n').trigger_load("bufferline.nvim")
|
||||||
};
|
'';
|
||||||
|
};
|
||||||
# Configure bufferline to load after catppuccin
|
|
||||||
plugins.bufferline = {
|
# Configure bufferline to load after catppuccin
|
||||||
enable = true;
|
plugins.bufferline = {
|
||||||
settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()";
|
enable = true;
|
||||||
lazyLoad.settings.lazy = true; # Lazy load manually
|
settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()";
|
||||||
};
|
lazyLoad.settings.lazy = true; # Lazy load manually
|
||||||
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue