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!"`
|
||||
|
||||
```nix
|
||||
foo = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = "Some string";
|
||||
default = null;
|
||||
example = "Hello, world!";
|
||||
{
|
||||
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).
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ in
|
|||
```
|
||||
|
||||
The extended `lib` is also accessible in the `lib` module argument in the `programs.nixvim` submodule:
|
||||
|
||||
```nix
|
||||
{
|
||||
programs.nixvim =
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ This function is recursive, meaning that it can be applied an arbitrary number o
|
|||
|
||||
```nix
|
||||
{makeNixvim}: let
|
||||
first = makeNixvim { extraConfigLua = "-- first stage"; };
|
||||
second = first.extend {extraConfigLua = "-- second stage";};
|
||||
third = second.extend {extraConfigLua = "-- third stage";};
|
||||
first = makeNixvim { extraConfigLua = "-- first stage"; };
|
||||
second = first.extend {extraConfigLua = "-- second stage";};
|
||||
third = second.extend {extraConfigLua = "-- third stage";};
|
||||
in
|
||||
third
|
||||
third
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```nix
|
||||
plugins.lsp.servers.nixd = {
|
||||
{
|
||||
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'';
|
||||
};
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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,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:
|
||||
|
||||
```nix
|
||||
extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
|
||||
{
|
||||
extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
|
||||
name = "my-plugin";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "<owner>";
|
||||
|
|
@ -44,7 +46,8 @@ extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
|
|||
rev = "<commit hash>";
|
||||
hash = "<nix NAR hash>";
|
||||
};
|
||||
})];
|
||||
})];
|
||||
}
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```nix
|
||||
keymaps =
|
||||
(builtins.map (key: {
|
||||
inherit key;
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}) ["<key-1>" "<key-2>" "<key-3>"])
|
||||
++ [
|
||||
# Other keymaps...
|
||||
];
|
||||
{
|
||||
keymaps =
|
||||
(builtins.map (key: {
|
||||
inherit key;
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}) ["<key-1>" "<key-2>" "<key-3>"])
|
||||
++ [
|
||||
# Other keymaps...
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to:
|
||||
|
||||
```nix
|
||||
keymaps = [
|
||||
{
|
||||
key = "<key-1>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
{
|
||||
key = "<key-2>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
{
|
||||
key = "<key-3>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
# Other keymaps...
|
||||
];
|
||||
{
|
||||
keymaps = [
|
||||
{
|
||||
key = "<key-1>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
{
|
||||
key = "<key-2>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
{
|
||||
key = "<key-3>";
|
||||
action = "<some-action>";
|
||||
options.desc = "My cool keymapping";
|
||||
}
|
||||
# Other keymaps...
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
[`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:
|
||||
```nix
|
||||
let
|
||||
nixvim = import (builtins.fetchGit {
|
||||
url = "https://github.com/nix-community/nixvim";
|
||||
# When using a different channel you can use `ref = "nixos-<version>"` to set it here
|
||||
});
|
||||
nixvim = import (builtins.fetchGit {
|
||||
url = "https://github.com/nix-community/nixvim";
|
||||
# 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:
|
||||
```nix
|
||||
{
|
||||
inputs.nixvim = {
|
||||
url = "github:nix-community/nixvim";
|
||||
# If using a stable channel you can use `url = "github:nix-community/nixvim/nixos-<version>"`
|
||||
};
|
||||
inputs.nixvim = {
|
||||
url = "github:nix-community/nixvim";
|
||||
# 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:
|
||||
|
||||
```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 = {
|
||||
{
|
||||
plugins.toggleterm = {
|
||||
enable = true;
|
||||
lazyLoad.settings = {
|
||||
cmd = "ToggleTerm";
|
||||
keys = [
|
||||
"<leader>tg"
|
||||
|
|
@ -91,36 +88,37 @@ 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 = ''
|
||||
function()
|
||||
require('lz.n').trigger_load('nvim-dap')
|
||||
end
|
||||
'';
|
||||
keys = [
|
||||
{
|
||||
__unkeyed-1 = "<leader>du";
|
||||
__unkeyed-2.__raw = ''
|
||||
function()
|
||||
require('dap.ext.vscode').load_launchjs(nil, {})
|
||||
require("dapui").toggle()
|
||||
end
|
||||
'';
|
||||
desc = "Toggle Debugger UI";
|
||||
}
|
||||
];
|
||||
};
|
||||
{
|
||||
plugins.dap-ui = {
|
||||
enable = true;
|
||||
lazyLoad.settings = {
|
||||
# We need to access nvim-dap in the after function.
|
||||
before.__raw = ''
|
||||
function()
|
||||
require('lz.n').trigger_load('nvim-dap')
|
||||
end
|
||||
'';
|
||||
keys = [
|
||||
{
|
||||
__unkeyed-1 = "<leader>du";
|
||||
__unkeyed-2.__raw = ''
|
||||
function()
|
||||
require('dap.ext.vscode').load_launchjs(nil, {})
|
||||
require("dapui").toggle()
|
||||
end
|
||||
'';
|
||||
desc = "Toggle Debugger UI";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```nix
|
||||
colorscheme = "catppuccin";
|
||||
colorschemes.catppuccin = {
|
||||
enable = true;
|
||||
lazyLoad.enable = true;
|
||||
};
|
||||
{
|
||||
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;
|
||||
lazyLoad.enable = true;
|
||||
{
|
||||
colorscheme = "catppuccin";
|
||||
colorschemes.catppuccin = {
|
||||
enable = true;
|
||||
lazyLoad.enable = true;
|
||||
|
||||
# This code runs after catppuccin is setup,
|
||||
# regardless of whether it was lazy-loaded or not.
|
||||
luaConfig.post = ''
|
||||
-- At this point catppuccin is configured, so we can safely
|
||||
-- derive bufferline highlights or similar settings from it.
|
||||
require('lz.n').trigger_load("bufferline.nvim")
|
||||
'';
|
||||
};
|
||||
# This code runs after catppuccin is setup,
|
||||
# regardless of whether it was lazy-loaded or not.
|
||||
luaConfig.post = ''
|
||||
-- At this point catppuccin is configured, so we can safely
|
||||
-- derive bufferline highlights or similar settings from it.
|
||||
require('lz.n').trigger_load("bufferline.nvim")
|
||||
'';
|
||||
};
|
||||
|
||||
# Configure bufferline to load after catppuccin
|
||||
plugins.bufferline = {
|
||||
enable = true;
|
||||
settings.highlights.__raw = "require('catppuccin.special.bufferline').get_theme()";
|
||||
lazyLoad.settings.lazy = true; # Lazy load manually
|
||||
};
|
||||
# Configure bufferline to load after catppuccin
|
||||
plugins.bufferline = {
|
||||
enable = true;
|
||||
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