# this file implements a keybind system, which is a higher level system # to configure vim.keymaps (note the different name bind vs map) { pkgs, lib, config, ... }: let keyRemap = mode: key: action: { inherit mode key action; }; keyCmd = mode: key: cmd: keyRemap mode key ":${cmd}"; in { # default binds config.vim.keybinds = { search-commands = keyCmd "n" "?" "FzfLua keymaps"; # user interface toggle-explorer = keyCmd "n" "e" "Neotree toggle"; reveal-active-file = keyCmd "n" "E" "Neotree reveal:Neotree focus"; lazygit = keyCmd "n" "gg" "FullscreenTerm ${pkgs.lazygit}/bin/lazygit"; smart-quit = keyCmd "n" "q" "SmartQuit"; # pickers pick-file = keyCmd "n" "" "FzfLua files"; pick-buffer = keyCmd "n" "b" "FzfLua buffers"; pick-mark = keyCmd "n" "'" "FzfLua marks"; pick-recent-command = keyCmd "n" "fc" "FzfLua command_history"; pick-other = keyCmd "n" "" "FzfLua builtin"; # picker of Fzf pickers find-fuzzy = keyCmd "n" "ff" "FzfLua grep_project"; find-grep = keyCmd "n" "fg" "FzfLua live_grep"; # lsp code-action = keyCmd "n" "ca" "FzfLua lsp_code_actions winopts.height=8 winopts.width=50 winopts.backdrop=100 winopts.title=false winopts.preview.title=false winopts.row=1 winopts.preview.hidden=true"; # subtle nice features visual-dedent = keyRemap "v" "<" "" ">gv"; # keep selection visual-overwrite = keyRemap "v" "p" "pgvygv"; # re-yank text clear-search-highlights = keyRemap "n" "" ":noh"; }; # implementation options.vim.keybinds = lib.mkOption { type = lib.types.attrsOf ( lib.types.nullOr ( lib.types.submodule { options = { mode = lib.mkOption { type = lib.types.str; }; key = lib.mkOption { type = lib.types.str; }; action = lib.mkOption { type = lib.types.str; }; }; } ) ); default = { }; }; config.vim.keymaps = let titleCase = str: lib.concatStringsSep " " ( map ( word: lib.strings.toUpper (builtins.substring 0 1 word) + builtins.substring 1 (builtins.stringLength word) word ) (lib.splitString "-" str) ); in builtins.filter (f: f != null) ( lib.attrsets.mapAttrsToList ( desc: bind: if bind != null then { desc = titleCase desc; inherit (bind) mode key action; } else null ) config.vim.keybinds ); }