about summary refs log tree commit diff stats
path: root/modules/home/conf/nvim/mappings/default.nix
blob: af800d22a29f6c671372eb611440d9c78eabc4a6 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{lib, ...}: {
  programs.nixvim = {
    globals = {
      mapleader = " ";
      maplocalleader = " ";
    };
    keymaps = [
      {
        mode = ["n" "i"];
        key = "<Esc>";
        action = "<cmd>noh<CR><Esc>";
        options.desc = "Disable the search highlighting and send Escape";
      }
      {
        key = "hh";
        mode = ["i"];
        action.__raw = ''
          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
        '';
        options.desc = "completion trigger/ forward in completen menu";
      }
      {
        key = "uu";
        mode = ["i"];
        action.__raw = ''
          function()
            local cmp = require('cmp');
            cmp.confirm()
          end
        '';
        options.desc = "confirm the selected item";
      }

      # FIXME: Add the below keymappings, when alacritty gets support for the kitty
      # keyboard protocol <2023-08-29>
      {
        # "<C-Tab>"
        key = "ztn";
        action = "<cmd>tabnext<CR>";
        options.desc = "cycle to the next tab";
      }
      {
        # "<S-C-Tab>"
        key = "ztp";
        action = "<cmd>tabprevious<CR>";
        options.desc = "cycle to the previous tab";
      }

      # yank/ cut to the system clipboard
      {
        key = "<leader>y";
        action = "\"+y";
        options.desc = "yank to the system clipboard";
      }
      {
        key = "<leader>Y";
        action = "\"+Y";
        options.desc = "yank until the end of the line to the system clipboard";
      }

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

      # Center the cursor vertically when moving to the next word during a search.
      {
        key = "l";
        action = "nzzzv";
        options.desc = "Center the cursor vertically when moving to the next word during a search.";
      }
      {
        key = "L";
        action = "Nzzzv";
        options.desc = "Center the cursor vertically when moving to the next word during a search.";
      }
      # remap the other keys to dvorak
      {
        key = "k";
        action = "t";
        options.desc = "go the the right on char";
      }
      {
        key = "K";
        action = "T";
        options.desc = "go to the left on char";
      }
      {
        key = "j";
        action = "k";
        options.desc = "go to the right before the char";
      }
      {
        key = "J";
        action = "K";
        options.desc = "go to the left before the char";
      }

      # Change Vim-keys
      {
        key = "h";
        action = "<left>";
        options.desc = "go left";
      }
      {
        key = "t";
        action = "g<down>";
        options.desc = "go down, with displaylines";
      }
      {
        key = "n";
        action = "g<up>";
        options.desc = "go up, with displaylines";
      }
      {
        key = "s";
        action = "<right>";
        options.desc = "go right";
      }

      # Move display lines
      {
        key = "0";
        action = "g0";
        options.desc = "go to the leftmost character in the screen line";
      }
      {
        key = "$";
        action = "g$";
        options.desc = "go to the rightmost character in the screen line";
      }
      {
        mode = ["n"];
        key = "<Enter>";
        action = "gf";
        options.desc = "open file/url under cursor";
      }
      {
        mode = ["n"];
        key = "<Tab>";
        action = ":";
        options.desc = "jump to command line";
      }

      {
        mode = ["n"];
        key = "\\f";
        action.__raw = "function() require('lf').start() end";
        options.desc = "open lf in a floating window";
      }

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

      {
        mode = ["n"];
        key = "<leader>p";
        action = "\"_dP";
        options.desc = "keep the cut thing in the base register";
      }
      {
        mode = ["n"];
        key = "<leader>c";
        action = "\"_c";
        options.desc = "change without saving to register";
      }

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

      {
        mode = ["n"];
        key = "<leader>s";
        action = ":%s/\\<<C-r><C-w>\\>/<C-r><C-w>/gI<Left><Left><Left>";
        options.desc = "replace for the word under the cursor";
      }

      {
        mode = ["n"];
        key = "<C-s>";
        action = "<cmd>mksession! <CR>";
        options.desc = "overwrite/create a session";
      }

      {
        mode = ["n"];
        key = "<leader>X";
        action = "!!$SHELL <CR>";
        options.desc = "Read the current line and execute that line in your $SHELL. The resulting output will replace the curent line that was being executed.";
      }
      {
        mode = ["t"];
        key = "<Esc><Esc>";
        action = "<C-\\><C-n>";
        options.desc = "Exit terminal mode with <Esc><Esc>";
      }

      # move selected lines in visual mode
      {
        mode = ["v"];
        key = "T";
        action = ":m '>+1<CR>gv=gv";
        options.desc = "move selected lines in visual mode down";
      }
      {
        mode = ["v"];
        key = "N";
        action = ":m '<-2<CR>gv=gv";
        options.desc = "move selected lines in visual mode up";
      }
    ];
  };
}