about summary refs log tree commit diff stats
path: root/home-manager/soispha/config/neovim/nixneovim/mappings/default.nix
blob: 8b38a1d0842052e11f256ae70684eefddb493e17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{lib, ...}: {
  programs.nixneovim = {
    globals = {
      mapleader = " ";
      maplocalleader = " ";
    };
    mapping = let
      normal_and_insert = {
        "<Esc>" = {
          action = "'<cmd>noh<CR><Esc>'";
          desc = "Disable the search highlighting and send Escape";
        };
      };
    in {
      insert =
        lib.recursiveUpate {
          "hh" = {
            action = ''
              function()
                local cmp = require('cmp');
                local luasnip = require('luasnip');

                if cmp.visible() then
                    cmp.select_next_item()
                elseif luasnip.expand_or_locally_jumpable() then
                    luasnip.expand_or_jump()
                end
              end
            '';
            desc = "completion trigger/ forward in completen menu";
          };
          "<S-Tab>" = {
            action = ''
              function()
                local cmp = require('cmp');
                cmp.confirm()
              end
            '';
            desc = "confirm the selected item";
          };
        }
        normal_and_insert;
      normalVisualOp = {
        # yank/ cut to the system clipboard
        "<leader>y" = "'\"+y'";
        "<leader>Y" = "'\"+Y'";

        # Unmap some old keys
        #"s" = "'<Nop>'";
        #"t" = "'<Nop>'";
        "<Up>" = "'<Nop>'";
        "<Down>" = "'<Nop>'";
        "<Left>" = "'<Nop>'";
        "<Right>" = "'<Nop>'";

        # remap dvorak
        "l" = "n";
        "L" = "N";
        "k" = "t";
        "K" = "T";
        "j" = "k";
        "J" = "K";

        # Change Vim-keys
        "h" = "<left>";
        "t" = "g<down>";
        "n" = "g<up>";
        "s" = "<right>";

        # Move display lines
        "0" = "g0";
        "$" = "g$";
      };
      normal =
        lib.recursiveUpdate {
          "<Tab>" = {
            action = "':'";
            desc = "jump to command line";
          };

          "N" = {
            action = "vim.diagnostic.goto_prev()";
            desc = "go to previous diagnostic message";
          };
          "T" = {
            action = "vim.diagnostic.goto_next()";
            desc = "go to next diagnostic message";
          };
          "<leader>e" = {
            action = "vim.diagnostic.open_float()";
            desc = "open float for the symbol";
          };
          "<leader>q" = {
            action = "vim.diagnostic.setloclist()";
            desc = "add buffer diagnostic to the location list (quick-fix)";
          };

          # Splits
          "<C-t>" = {
            action = "'<C-w>p'";
            desc = "go to previous split";
          };
          "<C-n>" = {
            action = "'<C-w>w'";
            desc = "go to next split";
          };
          "<leader>-" = {
            action = "'<C-W>s'";
            desc = "New horizontal split";
          };
          "<leader>|" = {
            action = "'<C-W>v'";
            desc = "New vertical split";
          };

          # Exit insert mode after creating a new line above or below the current line.";
          "o" = "'o<Esc>'";
          "O" = "'O<Esc>'";

          # Center the cursor vertically when moving to the next word during a search.
          "n" = "'nzzzv'";
          #"N" = "'Nzzzv'";

          "<leader>p" = {
            action = "'\"_dP'";
            desc = "keep the cut thing in the base register";
          };

          "<leader>d" = {
            action = "'\"_d'";
            desc = "delete without saving to register";
          };
          "dd" = {
            action = ''
              function()
                if vim.api.nvim_get_current_line():match("^%s*$") then
                  return '"_dd'
                else
                  return "dd"
                end
              end
            '';
            desc = "Pipe all blank line deletions to the blackhole register";
            expr = true;
            silent = true;
          };

          "<leader>s" = {
            action = "':%s/\\<<C-r><C-w>\\>/<C-r><C-w>/gI<Left><Left><Left>'";
            desc = "replace for the word under the cursor";
          };

          "<C-s>" = {
            action = "'<cmd>mksession! <CR>'";
            desc = "to overwrite/create a session";
          };

          "<leader>X" = {
            action = "'[[!!$SHELL <cr>]]'";
            desc = "Read the current line and execute that line in your $SHELL. The resulting output will replace the curent line that was being executed.";
          };
        }
        normal_and_insert;
      terminal = {
        "<Esc><Esc>" = {
          action = "'<C-\\><C-n>'";
          desc = "Exit terminal mode with <Esc><Esc>";
        };
      };
      visual = {
        # move selected lines in visual mode
        "T" = "':m '>+1<CR>gv=gv'";
        "N" = "':m '<-2<CR>gv=gv'";
      };
    };
  };
}