Surround setupopts (#402)

* surround: fix keymaps

* surround: make description multi-line
This commit is contained in:
diniamo 2024-10-06 13:35:07 +02:00 committed by GitHub
parent b637f921d5
commit 7a8b95cf7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 105 deletions

View file

@ -150,6 +150,8 @@ everyone.
- Replace `vim.lsp.nvimCodeActionMenu` with `vim.ui.fastaction`, see the - Replace `vim.lsp.nvimCodeActionMenu` with `vim.ui.fastaction`, see the
breaking changes section above for more details breaking changes section above for more details
- Add a `setupOpts` option to nvim-surround, which allows modifying options that aren't defined in nvf. Move the alternate nvim-surround keybinds to use `setupOpts`.
[Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd()
- Make Neovim's configuration file entirely Lua based. This comes with a few - Make Neovim's configuration file entirely Lua based. This comes with a few

View file

@ -3,42 +3,29 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.utility.surround; cfg = config.vim.utility.surround;
self = import ./surround.nix {inherit lib config;};
mappingDefinitions = self.options.vim.utility.surround.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = [ startPlugins = ["nvim-surround"];
"nvim-surround" pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})";
];
pluginRC.surround = entryAnywhere '' utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings {
require('nvim-surround').setup() insert = "<C-g>z";
''; insert_line = "<C-g>Z";
normal = "gz";
maps = { normal_cur = "gZ";
insert = mkMerge [ normal_line = "gzz";
(mkIf (mappings.insert != null) (mkSetBinding mappings.insert "<Plug>(nvim-surround-insert)")) normal_cur_line = "gZZ";
(mkIf (mappings.insertLine != null) (mkSetBinding mappings.insertLine "<Plug>(nvim-surround-insert-line)")) visual = "gz";
]; visual_line = "gZ";
normal = mkMerge [ delete = "gzd";
(mkIf (mappings.normal != null) (mkSetBinding mappings.normal "<Plug>(nvim-surround-normal)")) change = "gzr";
(mkIf (mappings.normalCur != null) (mkSetBinding mappings.normalCur "<Plug>(nvim-surround-normal-cur)")) change_line = "gZR";
(mkIf (mappings.normalLine != null) (mkSetBinding mappings.normalLine "<Plug>(nvim-surround-normal-line)"))
(mkIf (mappings.normalCurLine != null) (mkSetBinding mappings.normalCurLine "<Plug>(nvim-surround-normal-cur-line)"))
(mkIf (mappings.delete != null) (mkSetBinding mappings.delete "<Plug>(nvim-surround-delete)"))
(mkIf (mappings.change != null) (mkSetBinding mappings.change "<Plug>(nvim-surround-change)"))
];
visualOnly = mkMerge [
(mkIf (mappings.visual != null) (mkSetBinding mappings.visual "<Plug>(nvim-surround-visual)"))
(mkIf (mappings.visualLine != null) (mkSetBinding mappings.visualLine "<Plug>(nvim-surround-visual-line)"))
];
}; };
}; };
}; };

View file

@ -1,90 +1,24 @@
{ {lib, ...}: let
lib,
config,
...
}: let
inherit (lib.modules) mkIf mkDefault;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) bool nullOr str; inherit (lib.types) bool;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.utility.surround = { options.vim.utility.surround = {
enable = mkOption { enable = mkOption {
type = bool; type = bool;
default = false; default = false;
description = "nvim-surround: add/change/delete surrounding delimiter pairs with ease. Note that the default mappings deviate from upstreeam to avoid conflicts with nvim-leap."; description = ''
nvim-surround: add/change/delete surrounding delimiter pairs with ease.
Note that the default mappings deviate from upstreeam to avoid conflicts
with nvim-leap.
'';
}; };
setupOpts = mkPluginSetupOption "nvim-surround" {};
useVendoredKeybindings = mkOption { useVendoredKeybindings = mkOption {
type = bool; type = bool;
default = true; default = true;
description = "Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap"; description = "Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap";
}; };
mappings = {
insert = mkOption {
type = nullOr str;
default = "<C-g>z";
description = "Add surround character around the cursor";
};
insertLine = mkOption {
type = nullOr str;
default = "<C-g>Z";
description = "Add surround character around the cursor on new lines";
};
normal = mkOption {
type = nullOr str;
default = "gz";
description = "Surround motion with character";
};
normalCur = mkOption {
type = nullOr str;
default = "gZ";
description = "Surround motion with character on new lines";
};
normalLine = mkOption {
type = nullOr str;
default = "gzz";
description = "Surround line with character";
};
normalCurLine = mkOption {
type = nullOr str;
default = "gZZ";
description = "Surround line with character on new lines";
};
visual = mkOption {
type = nullOr str;
default = "gz";
description = "Surround selection with character";
};
visualLine = mkOption {
type = nullOr str;
default = "gZ";
description = "Surround selection with character on new lines";
};
delete = mkOption {
type = nullOr str;
default = "gzd";
description = "Delete surrounding character";
};
change = mkOption {
type = nullOr str;
default = "gzr";
description = "Change surrounding character";
};
};
};
config.vim.utility.surround = let
cfg = config.vim.utility.surround;
in {
mappings = mkIf (! cfg.useVendoredKeybindings) (mkDefault {
insert = null;
insertLine = null;
normal = null;
normalCur = null;
normalLine = null;
normalCurLine = null;
visual = null;
visualLine = null;
delete = null;
change = null;
});
}; };
} }