Compare commits
4 commits
f823ebd2ba
...
4a7c1b3d97
Author | SHA1 | Date | |
---|---|---|---|
4a7c1b3d97 | |||
8fe5adc810 | |||
88190d31a9 | |||
9e3e4b8345 |
7 changed files with 235 additions and 15 deletions
|
@ -39,9 +39,7 @@
|
|||
{
|
||||
packages = {
|
||||
default = nixeovimPackage { };
|
||||
base = nixeovimPackage profiles.base;
|
||||
recommended-plugins = nixeovimPackage profiles.recommended-plugins;
|
||||
};
|
||||
} // builtins.mapAttrs (k: nixeovimPackage) profiles;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
let
|
||||
types = import ./types.nix { inherit lib nix2lua; };
|
||||
mod = import ./mod.nix { inherit lib; };
|
||||
in
|
||||
lib // {
|
||||
inherit nix2lua;
|
||||
inherit nix2lua mod;
|
||||
|
||||
types = lib.types // types;
|
||||
}
|
||||
|
|
77
lib/mod.nix
Normal file
77
lib/mod.nix
Normal file
|
@ -0,0 +1,77 @@
|
|||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (builtins) listToAttrs;
|
||||
inherit (lib) nameValuePair toLower;
|
||||
|
||||
wrap = val: "<${val}>";
|
||||
|
||||
char = num: wrap "Char-${num}"; # map a character by its decimal, octal or hexadecimal number
|
||||
shift = key: wrap "S-${key}"; # shift-key *shift* *<S-*
|
||||
ctrl = key: wrap "C-${key}"; # control-key *control* *ctrl* *<C-*
|
||||
meta = key: wrap "M-${key}"; # alt-key or meta-key *META* *ALT* *<M-*
|
||||
super = key: wrap "D-${key}"; # command-key or "super" key *<D-*
|
||||
|
||||
keys = listToAttrs (map (v: nameValuePair v (wrap (toLower v))) (
|
||||
[
|
||||
"leader"
|
||||
"localLeader"
|
||||
"cmd"
|
||||
"plug"
|
||||
"mouseMove"
|
||||
|
||||
"nul"
|
||||
"bs"
|
||||
"tab"
|
||||
"nl"
|
||||
"cr"
|
||||
"esc"
|
||||
"space"
|
||||
"lt"
|
||||
"bslash"
|
||||
"bar"
|
||||
"del"
|
||||
"csi"
|
||||
"eol"
|
||||
"ignore"
|
||||
"nop"
|
||||
"up"
|
||||
"down"
|
||||
"left"
|
||||
"right"
|
||||
"help"
|
||||
"undo"
|
||||
"insert"
|
||||
"home"
|
||||
"end"
|
||||
"pageUp"
|
||||
"pageDown"
|
||||
"kUp"
|
||||
"kDown"
|
||||
"kLeft"
|
||||
"kRight"
|
||||
"kHome"
|
||||
"kEnd"
|
||||
"kOrigin"
|
||||
"kPageUp"
|
||||
"kPageDown"
|
||||
"kDel"
|
||||
"kPlus"
|
||||
"kMinus"
|
||||
"kMultiply"
|
||||
"kDivide"
|
||||
"kPoint"
|
||||
"kComma"
|
||||
"kEqual"
|
||||
"kEnter"
|
||||
]
|
||||
++ map (n: "F${toString n}") (lib.range 1 12)
|
||||
++ map (n: "k${toString n}") (lib.range 0 9)
|
||||
)
|
||||
);
|
||||
in
|
||||
{ inherit char shift ctrl meta super; } // keys // {
|
||||
return = keys.cr;
|
||||
enter = keys.cr;
|
||||
backslash = keys.bslash;
|
||||
}
|
|
@ -1,21 +1,23 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mod;
|
||||
|
||||
cfg = config.input;
|
||||
|
||||
disableKeymaps = mode: lhss: lib.flip map lhss (lhs: { inherit mode lhs; rhs = "<nop>"; });
|
||||
disableKeymaps = mode: lhss: lib.flip map lhss (lhs: { inherit mode lhs; rhs = mod.nop; });
|
||||
in
|
||||
{
|
||||
options.input = with lib; {
|
||||
leader = mkOption {
|
||||
type = types.str;
|
||||
default = ''\'';
|
||||
apply = x: assert (builtins.stringLength x == 1 || abort "<Leader> `${x}` is longer than one character is not allowed"); x;
|
||||
apply = x: assert (builtins.stringLength x == 1 || abort "${mod.leader} `${x}` is longer than one character is not allowed"); x;
|
||||
};
|
||||
localLeader = mkOption {
|
||||
type = types.str;
|
||||
default = ''\'';
|
||||
apply = x: assert (builtins.stringLength x == 1 || abort "<LocalLeader> `${x}` is longer than one character is not allowed"); x;
|
||||
apply = x: assert (builtins.stringLength x == 1 || abort "${mod.localLeader} `${x}` is longer than one character is not allowed"); x;
|
||||
};
|
||||
|
||||
exMode.enable = mkEnableOption "Ex mode";
|
||||
|
@ -43,15 +45,16 @@ in
|
|||
|
||||
config = {
|
||||
vim.g.mapleader = cfg.leader;
|
||||
vim.g.maplocalleader = cfg.localLeader;
|
||||
|
||||
vim.keymap.set =
|
||||
# Disable the annoying and useless ex-mode
|
||||
lib.optionals (!cfg.exMode.enable) (disableKeymaps "n" [ "Q" "gQ" ])
|
||||
# Disable arrow keys
|
||||
++ lib.optionals cfg.arrowKeys.disable
|
||||
(disableKeymaps cfg.arrowKeys.mode [ "<Up>" "<Down>" "<Left>" "<Right>" ])
|
||||
(disableKeymaps cfg.arrowKeys.mode [ mod.up mod.down mod.left mod.right ])
|
||||
# Disable PageUp / PageDown
|
||||
++ lib.optionals cfg.pageButtons.disable
|
||||
(disableKeymaps cfg.pageButtons.mode [ "<PageUp>" "<PageDown>" ]);
|
||||
(disableKeymaps cfg.pageButtons.mode [ mod.pageUp mod.pageDown ]);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ in
|
|||
defaultText = literalExpression "dir: []";
|
||||
example = literalExpression ''
|
||||
{ after, before }: [
|
||||
{ lhs = "<leader>hc"; rhs = "<CMD>HopChar1<CR>"; }
|
||||
{ lhs = "<leader>hc"; rhs = "<cmd>HopChar1<cr>"; }
|
||||
{
|
||||
lhs = "<leader>hf";
|
||||
rhs = lambda0 (call "hop.hint_char1" {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib.mod) leader cmd cr ctrl;
|
||||
in
|
||||
{
|
||||
vim.opt = {
|
||||
# Better Unix support
|
||||
|
@ -77,19 +80,24 @@
|
|||
plugins.navigation.nvim-tree.enable = lib.mkDefault true;
|
||||
|
||||
vim.keymap.set = with lib.nix2lua; [
|
||||
{ mode = "n"; lhs = "<C-z>"; rhs = lambda0 (set "vim.opt.hlsearch" false); desc = "Clear search highlighting"; }
|
||||
{
|
||||
mode = "n";
|
||||
lhs = ctrl "z";
|
||||
rhs = lambda0 (set "vim.opt.hlsearch" false);
|
||||
desc = "Clear search highlighting";
|
||||
}
|
||||
]
|
||||
++ lib.optionals config.plugins.navigation.nvim-tree.enable [
|
||||
{
|
||||
mode = "n";
|
||||
lhs = "<leader>nt";
|
||||
rhs = "<CMD>NvimTreeToggle<CR>";
|
||||
lhs = "${leader}nt";
|
||||
rhs = "${cmd}NvimTreeToggle${cr}";
|
||||
desc = "Open/Close file tree";
|
||||
}
|
||||
{
|
||||
mode = "n";
|
||||
lhs = "<leader>nf";
|
||||
rhs = "<CMD>NvimTreeFindFile<CR>";
|
||||
lhs = "${leader}nf";
|
||||
rhs = "${cmd}NvimTreeFindFile${cr}";
|
||||
desc = "Open file tree and find current file";
|
||||
}
|
||||
];
|
||||
|
|
133
modules/profiles/recommended.nix
Normal file
133
modules/profiles/recommended.nix
Normal file
|
@ -0,0 +1,133 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
with lib.nix2lua;
|
||||
let
|
||||
inherit (lib.mod) leader localLeader space cr cmd ctrl;
|
||||
gs = config.plugin.gitsigns-nvim.varName;
|
||||
hop = config.plugin.hop-nvim.varName;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./base.nix
|
||||
./recommended-plugins.nix
|
||||
];
|
||||
|
||||
input = {
|
||||
leader = lib.mkDefault ",";
|
||||
localLeader = lib.mkDefault "'";
|
||||
};
|
||||
|
||||
plugins.gitsigns.keymap.set = [
|
||||
rec {
|
||||
mode = "n";
|
||||
lhs = "]h";
|
||||
rhs = lambda0 (ifelse (var "vim.wo.diff")
|
||||
(call1 "vim.cmd.normal" [ lhs (nf "bang" true) ])
|
||||
(call1 "${gs}.nav_hunk" "next")
|
||||
);
|
||||
}
|
||||
rec {
|
||||
mode = "n";
|
||||
lhs = "[h";
|
||||
rhs = lambda0 (ifelse (var "vim.wo.diff")
|
||||
(call1 "vim.cmd.normal" [ lhs (nf "bang" true) ])
|
||||
(call1 "${gs}.nav_hunk" "prev")
|
||||
);
|
||||
}
|
||||
{ mode = "n"; lhs = "${localLeader}gs"; rhs = raw "${gs}.stage_hunk"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gr"; rhs = raw "${gs}.reset_hunk"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gu"; rhs = raw "${gs}.undo_stage_hunk"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gp"; rhs = raw "${gs}.preview_hunk"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gb"; rhs = lambda0 (call "${gs}.blame_line" { full = true; }); }
|
||||
{ mode = "n"; lhs = "${localLeader}gd"; rhs = raw "${gs}.diffthis"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gD"; rhs = lambda0 (call "${gs}.diffthis" "~"); }
|
||||
{ mode = "n"; lhs = "${localLeader}gtb"; rhs = raw "${gs}.toggle_current_line_blame"; }
|
||||
{ mode = "n"; lhs = "${localLeader}gtd"; rhs = raw "${gs}.toggle_deleted"; }
|
||||
];
|
||||
|
||||
plugins.navigation.hop-nvim.keymap.set = { after, before }: [
|
||||
{ lhs = "${leader}hc"; rhs = "${cmd}HopChar1${cr}"; }
|
||||
{
|
||||
lhs = "${leader}hf";
|
||||
rhs = lambda0 (call "${hop}.hint_char1" {
|
||||
direction = after;
|
||||
current_line_only = true;
|
||||
});
|
||||
}
|
||||
{
|
||||
lhs = "${leader}hF";
|
||||
rhs = lambda0 (call "${hop}.hint_char1" {
|
||||
direction = before;
|
||||
current_line_only = true;
|
||||
});
|
||||
}
|
||||
{
|
||||
lhs = "${leader}hbc";
|
||||
rhs = lambda0 (call "${hop}.hint_char1" { direction = after; });
|
||||
}
|
||||
{
|
||||
lhs = "${leader}htc";
|
||||
rhs = lambda0 (call "${hop}.hint_char1" { direction = before; });
|
||||
}
|
||||
{ lhs = "${leader}hw"; rhs = "${cmd}HopWord${cr}"; }
|
||||
{
|
||||
lhs = "${leader}hbw";
|
||||
rhs = lambda0 (call "${hop}.hint_words" { direction = after; });
|
||||
}
|
||||
{
|
||||
lhs = "${leader}htw";
|
||||
rhs = lambda0 (call "${hop}.hint_words" { direction = before; });
|
||||
}
|
||||
{ lhs = "${leader}hp"; rhs = "${cmd}HopPattern${cr}"; }
|
||||
{
|
||||
lhs = "${leader}hbp";
|
||||
rhs = lambda0 (call "${hop}.hint_patterns" { direction = after; });
|
||||
}
|
||||
{
|
||||
lhs = "${leader}htp";
|
||||
rhs = lambda0 (call "${hop}.hint_patterns" { direction = before; });
|
||||
}
|
||||
{
|
||||
lhs = "${leader}hbv";
|
||||
rhs = lambda0 (call "${hop}.hint_vertical" { direction = after; });
|
||||
}
|
||||
{
|
||||
lhs = "${leader}htv";
|
||||
rhs = lambda0 (call "${hop}.hint_vertical" { direction = before; });
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
plugins.language-server.lspconfig.keymap.set = [
|
||||
{ mode = "n"; lhs = "gD"; rhs = raw "vim.lsp.buf.declaration"; }
|
||||
{ mode = "n"; lhs = "gd"; rhs = raw "vim.lsp.buf.definition"; }
|
||||
{ mode = "n"; lhs = "K"; rhs = raw "vim.lsp.buf.hover"; }
|
||||
{ mode = "n"; lhs = "gi"; rhs = raw "vim.lsp.buf.implementation"; }
|
||||
{ mode = "n"; lhs = "gr"; rhs = raw "vim.lsp.buf.references"; }
|
||||
{ mode = "n"; lhs = "gy"; rhs = raw "vim.lsp.buf.type_definition"; }
|
||||
{ mode = "n"; lhs = ctrl "k"; rhs = raw "vim.lsp.buf.signature_help"; }
|
||||
{ mode = "n"; lhs = "${localLeader}n"; rhs = raw "vim.lsp.buf.rename"; }
|
||||
{ mode = [ "n" "v" ]; lhs = "${localLeader}a"; rhs = raw "vim.lsp.buf.code_action"; }
|
||||
];
|
||||
|
||||
vim.keymap.set = lib.optionals config.plugins.language-server.lspconfig.enable [
|
||||
{ mode = "n"; lhs = "${space}e"; rhs = raw "vim.diagnostic.open_float"; }
|
||||
{ mode = "n"; lhs = "[d"; rhs = raw "vim.diagnostic.goto_prev"; }
|
||||
{ mode = "n"; lhs = "]d"; rhs = raw "vim.diagnostic.goto_next"; }
|
||||
{ mode = "n"; lhs = "${space}q"; rhs = raw "vim.diagnostic.setloclist"; }
|
||||
] ++ lib.optionals config.plugins.navigation.telescope.enable (
|
||||
[
|
||||
{ mode = "n"; lhs = "${leader}ff"; rhs = "${cmd}Telescope find_files${cr}"; }
|
||||
{ mode = "n"; lhs = "${leader}fb"; rhs = "${cmd}Telescope buffers${cr}"; }
|
||||
{ mode = "n"; lhs = "${leader}fh"; rhs = "${cmd}Telescope help_tags${cr}"; }
|
||||
] ++ lib.optionals (config.plugins.navigation.telescope.extensions ? telescope-live-grep-args-nvim) [
|
||||
{
|
||||
mode = "n";
|
||||
lhs = "${leader}fg";
|
||||
rhs = lambda0 (call0 "telescope.extensions.live_grep_args.live_grep_args");
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue