From 9450dca78f73c920fd668cd3c9150ae397608816 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 15 May 2024 22:46:01 +0200 Subject: nixvim: add unimpaired-style option toggle keymaps --- common/nixvim.nix | 236 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 139 insertions(+), 97 deletions(-) diff --git a/common/nixvim.nix b/common/nixvim.nix index 526e55d..29e8add 100644 --- a/common/nixvim.nix +++ b/common/nixvim.nix @@ -96,87 +96,123 @@ in TSDefinitionUsage.link = "GruvboxAquaSign"; }; - keymaps = [ - { - key = "fu"; - action = "require('telescope').extensions.undo.undo"; - lua = true; - options = { - silent = true; - desc = "Telescope undo"; + keymaps = + let + toggle = key: option: { + key = "yo${key}"; + action = "setlocal ${option}! ${option}?"; + options.desc = "Toggle ${option}"; }; - } - - { - key = "-"; - action = "require('oil').open"; - lua = true; - options.desc = "Open parent directory"; - } - - # TODO: add "] " and "[ " - - # Gitsigns - - # TODO: that was not exactly that - # { - # key = "]g"; - # action = "require('gitsigns').next_hunk"; - # lua = true; - # } - - # TODO: noremap? buffer local? silent? - { - key = "gs"; - action = "require('gitsigns').stage_hunk"; - lua = true; - options.desc = "Stage hunk"; - } - - { - key = "gr"; - action = "require('gitsigns').reset_hunk"; - lua = true; - options.desc = "Reset hunk"; - } - - # TODO: visual stage/reset - - { - key = "gS"; - action = "require('gitsigns').stage_buffer"; - lua = true; - options.desc = "Stage buffer"; - } - - { - key = "gR"; - action = "require('gitsigns').reset_buffer"; - lua = true; - options.desc = "Stage buffer"; - } - - { - key = "gu"; - action = "require('gitsigns').undo_stage_hunk"; - lua = true; - options.desc = "Undo stage hunk"; - } - - { - key = "gp"; - action = "require('gitsigns').preview_hunk_inline"; - lua = true; - options.desc = "Preview hunk"; - } - - { - key = "gb"; - action = "function() require('gitsigns').blame_line { full = true } end"; - lua = true; - options.desc = "Blame line"; - } - ]; + in + [ + { + key = "fu"; + action = "require('telescope').extensions.undo.undo"; + lua = true; + options = { + silent = true; + desc = "Telescope undo"; + }; + } + + { + key = "-"; + action = "require('oil').open"; + lua = true; + options.desc = "Open parent directory"; + } + + # TODO: add "] " and "[ " + + # Gitsigns + + # TODO: that was not exactly that + # { + # key = "]g"; + # action = "require('gitsigns').next_hunk"; + # lua = true; + # } + + # TODO: noremap? buffer local? silent? + { + key = "gs"; + action = "require('gitsigns').stage_hunk"; + lua = true; + options.desc = "Stage hunk"; + } + + { + key = "gr"; + action = "require('gitsigns').reset_hunk"; + lua = true; + options.desc = "Reset hunk"; + } + + # TODO: visual stage/reset + + { + key = "gS"; + action = "require('gitsigns').stage_buffer"; + lua = true; + options.desc = "Stage buffer"; + } + + { + key = "gR"; + action = "require('gitsigns').reset_buffer"; + lua = true; + options.desc = "Stage buffer"; + } + + { + key = "gu"; + action = "require('gitsigns').undo_stage_hunk"; + lua = true; + options.desc = "Undo stage hunk"; + } + + { + key = "gp"; + action = "require('gitsigns').preview_hunk_inline"; + lua = true; + options.desc = "Preview hunk"; + } + + { + key = "gb"; + action = "function() require('gitsigns').blame_line { full = true } end"; + lua = true; + options.desc = "Blame line"; + } + + # Toggle options + (toggle "c" "cursorline") + (toggle "C" "cursorcolumn") + (toggle "h" "hlsearch") + (toggle "i" "ignorecase") + (toggle "l" "list") + (toggle "n" "number") + (toggle "r" "relativenumber") + (toggle "s" "spell") + (toggle "w" "wrap") + + { + key = "yod"; + action = '' + function() + if vim.wo.diff then + vim.cmd.diffoff() + print('diffoff') + else + vim.cmd.diffthis() + print('diffthis') + end + end + ''; + lua = true; + options.desc = "Toggle diff"; + } + ]; # TODO: # extraPlugins = with pkgs.unstable.vimPlugins; [ @@ -306,6 +342,10 @@ in bracketed = { }; clue = { triggers = [ + { + mode = "n"; + keys = "yo"; + } { mode = "n"; keys = "["; @@ -461,23 +501,25 @@ in enable = true; lookahead = true; # selectionModes = "V"; - keymaps = let - keymap = object: type: { - query = "@${object}.${type}"; - desc = "Select ${type} ${object}"; + keymaps = + let + keymap = object: type: { + query = "@${object}.${type}"; + desc = "Select ${type} ${object}"; + }; + in + { + "af" = keymap "function" "outer"; + "if" = keymap "function" "inner"; + "aF" = keymap "call" "outer"; + "iF" = keymap "call" "inner"; + "aC" = keymap "comment" "outer"; + "iC" = keymap "comment" "inner"; + "ab" = keymap "block" "outer"; + "ib" = keymap "block" "inner"; + "aa" = keymap "parameter" "outer"; + "ia" = keymap "parameter" "inner"; }; - in { - "af" = keymap "function" "outer"; - "if" = keymap "function" "inner"; - "aF" = keymap "call" "outer"; - "iF" = keymap "call" "inner"; - "aC" = keymap "comment" "outer"; - "iC" = keymap "comment" "inner"; - "ab" = keymap "block" "outer"; - "ib" = keymap "block" "inner"; - "aa" = keymap "parameter" "outer"; - "ia" = keymap "parameter" "inner"; - }; }; }; }; @@ -506,5 +548,5 @@ in ''; }; - config.environment.systemPackages = [config.programs.nixvim.finalPackage]; + config.environment.systemPackages = [ config.programs.nixvim.finalPackage ]; } -- cgit v1.2.3