{ config, lib, ... }: { programs.nixvim = { globals = { mapleader = " "; maplocalleader = " "; }; keymaps = let normal = lib.mapAttrsToList (key: action: { mode = "n"; inherit action key; }) { "" = ""; # Esc to clear search results "" = ":noh"; # fix Y behavior Y = "y$"; # toggle between two most recent files "" = ":b#"; # close by Ctrl+x "" = ":close"; # save by Space+s or Ctrl+s "s" = ":w"; "" = ":w"; # H, L to jump to start/end of line L = "$"; H = "^"; # resize with arrows "" = ":resize -2"; "" = ":resize +2"; "" = ":vertical resize +2"; "" = ":vertical resize -2"; # move current line up/down # M = Alt "" = ":move-2"; "" = ":move+"; }; visual = lib.mapAttrsToList (key: action: { mode = "v"; inherit action key; }) { # better indenting ">" = ">gv"; "<" = "" = ">gv"; "" = "s" = ":sort"; }; insert = lib.mapAttrsToList (key: action: { mode = "i"; inherit action key; }) { # Save by Ctrl+s "" = ":w"; }; in config.lib.nixvim.keymaps.mkKeymaps {options.silent = true;} (normal ++ visual ++ insert); }; }