dotfiles/home/modules/tui/neovim/keymaps.nix

75 lines
1.7 KiB
Nix
Raw Permalink Normal View History

2024-12-05 03:11:13 +00:00
{ config, lib, ... }: {
programs.nixvim = {
globals = {
mapleader = " ";
maplocalleader = " ";
};
keymaps = let
2024-12-20 01:30:06 +00:00
normal = lib.mapAttrsToList (key: action: {
mode = "n";
inherit action key;
}) {
"<Space>" = "<NOP>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# Esc to clear search results
"<esc>" = ":noh<CR>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# fix Y behavior
Y = "y$";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# toggle between two most recent files
"<C-c>" = ":b#<CR>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# close by Ctrl+x
"<C-x>" = ":close<CR>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# save by Space+s or Ctrl+s
"<leader>s" = ":w<CR>";
"<C-s>" = ":w<CR>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# H, L to jump to start/end of line
L = "$";
H = "^";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# resize with arrows
"<C-Up>" = ":resize -2<CR>";
"<C-Down>" = ":resize +2<CR>";
"<C-Left>" = ":vertical resize +2<CR>";
"<C-Right>" = ":vertical resize -2<CR>";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# move current line up/down
# M = Alt
"<M-k>" = ":move-2<CR>";
"<M-j>" = ":move+<CR>";
};
visual = lib.mapAttrsToList (key: action: {
mode = "v";
inherit action key;
}) {
# better indenting
">" = ">gv";
"<" = "<gv";
"<TAB>" = ">gv";
"<S-TAB>" = "<gv";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# move selected line/block in visual mode
"K" = ":m '<-2<CR>gv=gv";
"J" = ":m '>+1<CR>gv=gv";
2024-12-05 03:11:13 +00:00
2024-12-20 01:30:06 +00:00
# sort
"<leader>s" = ":sort<CR>";
};
insert = lib.mapAttrsToList (key: action: {
mode = "i";
inherit action key;
}) {
# Save by Ctrl+s
"<C-s>" = "<Esc>:w<CR>";
};
in config.lib.nixvim.keymaps.mkKeymaps { options.silent = true; }
(normal ++ visual ++ insert);
2024-12-05 03:11:13 +00:00
};
2024-12-05 04:50:49 +00:00
}