1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-17 14:31:11 +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

@ -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

View file

@ -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...
}
```

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 = {
{
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;
# 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
};
{
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")
'';
};
# 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
};
}
```