From b1e109a6fe4f362a4ca540be89f6705192b5b142 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 6 Nov 2024 10:41:10 -0500 Subject: [PATCH] global/neovim: redo keybindings with leader key --- users/modules/global/neovim.nix | 61 ++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/users/modules/global/neovim.nix b/users/modules/global/neovim.nix index e3591ec..2304fc7 100644 --- a/users/modules/global/neovim.nix +++ b/users/modules/global/neovim.nix @@ -1,4 +1,20 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: +let + flattenTree = lib.our.flattenTree' (val: val ? action) ""; + + mkLeader = { leader, mode }: name: value: { + key = leader + name; + inherit mode; + } // value; + + mkLeaderMap = tree: + builtins.concatMap + (leader: lib.mapAttrsToList (mkLeader leader) (flattenTree tree)) + [ + { leader = ""; mode = [ "n" "v" ]; } + { leader = ""; mode = [ "n" "v" "i" ]; } + ]; +in { programs.nixvim = { enable = true; @@ -29,7 +45,7 @@ doom-one-nvim ]; - globals.mapleader = ""; + globals.mapleader = " "; autoCmd = [ { event = [ "TermOpen" ]; command = "setlocal nonumber norelativenumber"; } @@ -37,16 +53,43 @@ keymaps = [ { - key = " n"; + key = ""; + action = ""; + mode = [ "n" "v" ]; + options = { + silent = true; + }; + } + { + key = "n"; action = ""; mode = "t"; } - { - key = ""; - action.__raw = "vim.lsp.buf.code_action"; - mode = [ "n" "i" "v" "s" ]; - } - ]; + ] ++ mkLeaderMap { + c = { + a.action.__raw = "vim.lsp.buf.code_action"; + f.action = ":Format"; + t = { + f.action = ":FormatToggle"; + }; + }; + w = { + q.action = ":close"; + v.action = ":vsplit"; + s.action = ":split"; + V.action = ":vsplit "; + S.action = ":split "; + n.action = ":next"; + p.action = ":previous"; + }; + f = { + s.action = ":w"; + }; + q = { + q.action = ":q"; + x.action = ":x"; + }; + }; plugins = { autoclose = {