mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-07 16:05:58 +01:00
Merge pull request #158 from ksonj/feature/surround-mappings
utility/surround: Add mappings for nvim-surround
This commit is contained in:
commit
897493a65f
3 changed files with 118 additions and 9 deletions
|
@ -69,3 +69,7 @@ https://github.com/jacekpoz[jacekpoz]:
|
||||||
* Updated clangd to 16
|
* Updated clangd to 16
|
||||||
|
|
||||||
* Disabled `useSystemClipboard` by default
|
* Disabled `useSystemClipboard` by default
|
||||||
|
|
||||||
|
https://github.com/ksonj[ksonj]:
|
||||||
|
|
||||||
|
* Add support to change mappings to utility/surround
|
||||||
|
|
|
@ -6,14 +6,38 @@
|
||||||
with lib;
|
with lib;
|
||||||
with builtins; let
|
with builtins; let
|
||||||
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.startPlugins = [
|
vim = {
|
||||||
|
startPlugins = [
|
||||||
"nvim-surround"
|
"nvim-surround"
|
||||||
];
|
];
|
||||||
|
|
||||||
vim.luaConfigRC.surround = nvim.dag.entryAnywhere ''
|
luaConfigRC.surround = nvim.dag.entryAnywhere ''
|
||||||
require('nvim-surround').setup()
|
require('nvim-surround').setup()
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
maps = {
|
||||||
|
insert = mkMerge [
|
||||||
|
(mkIf (mappings.insert != null) (mkSetBinding mappings.insert "<Plug>(nvim-surround-insert)"))
|
||||||
|
(mkIf (mappings.insertLine != null) (mkSetBinding mappings.insertLine "<Plug>(nvim-surround-insert-line)"))
|
||||||
|
];
|
||||||
|
normal = mkMerge [
|
||||||
|
(mkIf (mappings.normal != null) (mkSetBinding mappings.normal "<Plug>(nvim-surround-normal)"))
|
||||||
|
(mkIf (mappings.normalCur != null) (mkSetBinding mappings.normalCur "<Plug>(nvim-surround-normal-cur)"))
|
||||||
|
(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)"))
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,88 @@
|
||||||
{lib, ...}:
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
with lib;
|
with lib;
|
||||||
with builtins; {
|
with builtins; {
|
||||||
options.vim.utility.surround = {
|
options.vim.utility.surround = {
|
||||||
enable = mkEnableOption "nvim-surround: add/change/delete surrounding delimiter pairs with ease";
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
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.";
|
||||||
|
};
|
||||||
|
useVendoredKeybindings = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap";
|
||||||
|
};
|
||||||
|
mappings = {
|
||||||
|
insert = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "<C-g>z";
|
||||||
|
description = "Add surround character around the cursor";
|
||||||
|
};
|
||||||
|
insertLine = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "<C-g>Z";
|
||||||
|
description = "Add surround character around the cursor on new lines";
|
||||||
|
};
|
||||||
|
normal = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gz";
|
||||||
|
description = "Surround motion with character";
|
||||||
|
};
|
||||||
|
normalCur = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gZ";
|
||||||
|
description = "Surround motion with character on new lines";
|
||||||
|
};
|
||||||
|
normalLine = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gzz";
|
||||||
|
description = "Surround line with character";
|
||||||
|
};
|
||||||
|
normalCurLine = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gZZ";
|
||||||
|
description = "Surround line with character on new lines";
|
||||||
|
};
|
||||||
|
visual = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gz";
|
||||||
|
description = "Surround selection with character";
|
||||||
|
};
|
||||||
|
visualLine = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gZ";
|
||||||
|
description = "Surround selection with character on new lines";
|
||||||
|
};
|
||||||
|
delete = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "gzd";
|
||||||
|
description = "Delete surrounding character";
|
||||||
|
};
|
||||||
|
change = mkOption {
|
||||||
|
type = types.nullOr types.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;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue