nix-community.nixvim/plugins/utils/improved-search.nix

129 lines
3.2 KiB
Nix
Raw Normal View History

2024-04-13 11:46:57 +02:00
{
lib,
helpers,
...
}:
with lib;
# This plugin is only configured through keymaps, so we use `mkVimPlugin` without the
# `globalPrefix` argument to avoid the creation of the `settings` option.
helpers.vim-plugin.mkVimPlugin {
2024-05-05 19:39:35 +02:00
name = "improved-search";
originalName = "improved-search.nvim";
package = "improved-search-nvim";
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
maintainers = [ maintainers.GaetanLepage ];
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
extraOptions = {
keymaps = mkOption {
description = ''
Keymap definitions for search functions
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
See [here](https://github.com/backdround/improved-search.nvim?tab=readme-ov-file#functions-and-operators) for the list of available callbacks.
'';
type =
with helpers.nixvimTypes;
listOf (submodule {
options = {
key = mkOption {
type = str;
description = "The key to map.";
example = "!";
};
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
mode = helpers.keymaps.mkModeOption "";
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
action = mkOption {
type =
with helpers.nixvimTypes;
maybeRaw (
# https://github.com/backdround/improved-search.nvim?tab=readme-ov-file#functions-and-operators
enum [
"stable_next"
"stable_previous"
"current_word"
"current_word_strict"
"in_place"
"in_place_strict"
"forward"
"forward_strict"
"backward"
"backward_strict"
]
);
description = ''
The action to execute.
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
See [here](https://github.com/backdround/improved-search.nvim?tab=readme-ov-file#functions-and-operators) for the list of available callbacks.
'';
example = "in_place";
};
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
options = helpers.keymaps.mapConfigOptions;
};
});
default = [ ];
example = [
{
mode = [
"n"
"x"
"o"
];
key = "n";
action = "stable_next";
}
{
mode = [
"n"
"x"
"o"
];
key = "N";
action = "stable_previous";
}
{
mode = "n";
key = "!";
action = "current_word";
options.desc = "Search current word without moving";
}
{
mode = "x";
key = "!";
action = "in_place";
}
{
mode = "x";
key = "*";
action = "forward";
}
{
mode = "x";
key = "#";
action = "backward";
}
{
mode = "n";
key = "|";
action = "in_place";
}
];
2024-04-13 11:46:57 +02:00
};
2024-05-05 19:39:35 +02:00
};
2024-04-13 11:46:57 +02:00
2024-05-05 19:39:35 +02:00
extraConfig = cfg: {
keymaps = map (keymap: {
inherit (keymap) key options mode;
action =
if
isString keymap.action
# One of the plugin builtin functions
then
helpers.mkRaw "require('improved-search').${keymap.action}"
# If the user specifies a raw action directly
else
keymap.action;
}) cfg.keymaps;
};
}