-
Notifications
You must be signed in to change notification settings - Fork 2
/
helix.nix
464 lines (416 loc) · 13 KB
/
helix.nix
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
{
pkgs,
config,
lib,
inputs,
...
}:
with lib;
let
cfg = config.my.programs.helix;
language = name: text: text;
myTheme = "gruvbox_clo4";
in
{
options = {
my.programs.helix.enable = mkEnableOption "my helix configuration";
};
config = mkIf cfg.enable {
# Might have to refactor this into a module or upstream it if I add more queries!
xdg.configFile."helix/runtime/queries/nix/injections.scm".text =
let
# Helix will override whatever the builtin injection query is with your own
# if you don't copy it and append your query to it.
originalNixInjections = builtins.readFile (inputs.helix + "/runtime/queries/nix/injections.scm");
in
language "scheme" ''
; This is a simple query that allows you to define a function called "language" and
; highlight as whatever its first argument is. `language = name: str: str;`
((apply_expression
function: (apply_expression function: (_) @_func
argument: (string_expression (string_fragment) @injection.language))
argument: (indented_string_expression (string_fragment) @injection.content))
(#eq? @_func "language")
(#set! injection.language))
${originalNixInjections}
'';
xdg.configFile."helix/runtime/queries/go/injections.scm".text =
let
originalGoInjections = builtins.readFile (inputs.helix + "/runtime/queries/go/injections.scm");
in
language "scheme" ''
; Inject SQL as the first argument to the standard library's SQL methods.
; These methods take `sqlString` as the first argument
((call_expression
function: (selector_expression
operand: (_)
field: (field_identifier) @_method (#any-of? @_method "Query" "QueryRow" "Exec" "Prepare"))
arguments: (argument_list
.
[(interpreted_string_literal) (raw_string_literal)] @injection.content))
(#set! injection.language "sql"))
; Inject SQL as the second argument to all the different SQL query methods.
; This supports the style that PGX uses the same names as the standard library
; but take a context as the first argument.
((call_expression
function: (selector_expression
operand: (_)
field: (field_identifier) @_method (#any-of? @_method "Query" "QueryRow" "QueryContext" "QueryRowContext" "Exec" "ExecContext" "Prepare" "PrepareContext"))
arguments: (argument_list
. (_)
. [(interpreted_string_literal) (raw_string_literal)] @injection.content))
(#set! injection.language "sql"))
${originalGoInjections}
'';
programs.helix = {
enable = true;
defaultEditor = true;
package = inputs.helix.packages.${pkgs.stdenv.system}.default;
# # nu syntax has been updated a fair bit since the last update to the default language file
# package = inputs.helix.packages.${pkgs.stdenv.system}.default.override {
# grammarOverlays = [
# (final: prev: {
# nu = prev.nu.overrideAttrs {
# rev = "2d0dd587dbfc3363d2af4e4141833e718647a67e";
# };
# })
# ];
# };
settings = {
theme = "gruvbox";
# theme = myTheme;
editor = {
# Override because every terminal I use supports true color, but
# sometimes helix fails to detect it over ssh, tmux, etc.
true-color = true;
color-modes = true;
line-number = "relative";
idle-timeout = 0;
completion-trigger-len = 1;
bufferline = "multiple";
};
editor.statusline = {
right = [
"diagnostics"
"selections"
"position"
"position-percentage"
"file-encoding"
];
};
editor.cursor-shape = {
insert = "bar";
select = "underline";
normal = "block";
};
editor.indent-guides = {
render = true;
character = "▏";
skip-levels = 1;
};
editor.whitespace = {
render.newline = "all";
characters.newline = "↵";
};
editor.lsp = {
display-messages = true;
display-inlay-hints = true;
};
editor.inline-diagnostics = {
cursor-line = "hint";
other-lines = "hint";
};
keys.normal = {
# This goes against the Helix way of selection->action but it's a
# common enough thing to warrant making it its own keybind.
# D = ["goto_first_nonwhitespace" "extend_to_line_end" "change_selection"];
# Mode switching always happens at the end of the list of commands, so
# the order that these are in doesn't matter because collapsing the selection
# will always happen first.
a = [
"append_mode"
"collapse_selection"
];
i = [
"insert_mode"
"collapse_selection"
];
# Mnemonic: control hints
C-h = ":toggle-option lsp.display-inlay-hints";
# By default, Helix tries to leave the cursor where it was when scrolling
C-d = [
"half_page_down"
"goto_window_center"
];
C-u = [
"half_page_up"
"goto_window_center"
];
# Searching for a selection probably shouldn't have whitespace included.
# Makes sense to keep the default keybind in select mode though?
"*" = [
"trim_selections"
"search_selection"
"select_mode"
];
};
keys.normal.C-q = ":quit-all";
keys.normal.C-w = ":quit";
keys.normal.space.d = "vsplit";
keys.select.space.d = "vsplit";
keys.normal.space.D = "hsplit";
keys.select.space.D = "hsplit";
keys.normal.C-r = ":reload";
keys.normal.C-R = ":reload-all";
keys.normal.space.u = ":reset-diff-change";
keys.normal.D = "goto_word";
keys.select.D = "extend_to_word";
# keys.normal.V = "add_selection_on_word";
# keys.select.V = "add_selection_on_word";
keys.normal.S-left = "jump_view_left";
keys.select.S-left = "jump_view_left";
keys.normal.S-right = "jump_view_right";
keys.select.S-right = "jump_view_right";
keys.normal.S-up = "jump_view_up";
keys.select.S-up = "jump_view_up";
keys.normal.S-down = "jump_view_down";
keys.select.S-down = "jump_view_down";
# lots of repetition. if only there was a configuration language with functions that
# compiled to the desired end format. oh well
keys.normal."`" = {
c = [
"trim_selections"
":pipe ccase --to camel"
];
C = [
"trim_selections"
":pipe ccase --to uppercamel"
];
s = [
"trim_selections"
":pipe ccase --to snake"
];
S = [
"trim_selections"
":pipe ccase --to screamingsnake"
];
k = [
"trim_selections"
":pipe ccase --to kebab"
];
K = [
"trim_selections"
":pipe ccase --to upperkebab"
];
t = [
"trim_selections"
":pipe ccase --to title"
];
r = [
"trim_selections"
":pipe ccase --to pseudorandom"
];
};
keys.select."`" = {
c = [
"trim_selections"
":pipe ccase --to camel"
];
C = [
"trim_selections"
":pipe ccase --to uppercamel"
];
s = [
"trim_selections"
":pipe ccase --to snake"
];
S = [
"trim_selections"
":pipe ccase --to screamingsnake"
];
k = [
"trim_selections"
":pipe ccase --to kebab"
];
K = [
"trim_selections"
":pipe ccase --to upperkebab"
];
t = [
"trim_selections"
":pipe ccase --to title"
];
r = [
"trim_selections"
":pipe ccase --to pseudorandom"
];
};
# These are unbound by default, probably because there's not really a good reason
# to use them. But because I use the arrow keys on the home row of my keyboard (hjkl
# are in other locations because I use an alternate keyboard layout) I need to
# add the bindings for them.
keys.normal.g = {
left = "goto_line_start";
right = "goto_line_end";
up = "move_line_up";
down = "move_line_down";
};
keys.select.g = {
left = "goto_line_start";
right = "goto_line_end";
up = "move_line_up";
down = "move_line_down";
};
keys.normal.Z =
let
repeat = count: thing: if count < 2 then [ thing ] else [ thing ] ++ repeat (count - 1) thing;
in
{
C-d = [
"half_page_down"
"goto_window_center"
];
C-u = [
"half_page_up"
"goto_window_center"
];
d = "scroll_down";
u = "scroll_up";
e = "scroll_down";
y = "scroll_up";
# upper case should move more than one line but less than a half page
J = repeat 5 "scroll_down";
K = repeat 5 "scroll_up";
D = repeat 5 "scroll_down";
U = repeat 5 "scroll_up";
E = repeat 5 "scroll_down";
Y = repeat 5 "scroll_up";
};
keys.normal.space.w = {
V = [
"vsplit_new"
"file_picker"
];
S = [
"hsplit_new"
"file_picker"
];
};
keys.select = {
# Mode switching always happens at the end of the list of commands, so
# the order that these are in doesn't matter because collapsing the selection
# will always happen first.
a = [
"append_mode"
"collapse_selection"
];
i = [
"insert_mode"
"collapse_selection"
];
C-h = ":toggle-option lsp.display-inlay-hints";
C-d = [
"half_page_down"
"goto_window_center"
];
C-u = [
"half_page_up"
"goto_window_center"
];
# When I collapse a selection in select mode, the next thing I do
# is *always* enter normal mode.
";" = [
"collapse_selection"
"normal_mode"
];
};
keys.insert = {
C-h = ":toggle-option lsp.display-inlay-hints";
# This is a pretty standard shortcut in most editors
C-space = "completion";
};
};
themes.${myTheme} = {
inherits = "gruvbox";
comment.fg = "gray1";
"ui.virtual.jump-label" = {
fg = "purple0";
bg = "bg-1";
modifiers = [ "bold" ];
};
palette.bg-1 = "#141414";
};
languages.language-server = {
deno = {
command = "deno";
args = [ "lsp" ];
config = {
enable = true;
unstable = true;
lint = true;
};
};
vtsls = {
command = "vtsls";
args = [ "--stdio" ];
};
svelteserver.command = "svelteserver";
tailwindcss = {
command = "tailwindcss-language-server";
language-id = "tailwindcss";
args = [ "--stdio" ];
config = { };
};
rust-analyzer = {
command = "rust-analyzer";
config.check.command = "clippy";
};
ltex-ls.command = "ltex-ls";
};
languages.language = [
{
name = "go";
auto-format = true;
formatter = {
command = "goimports";
};
}
{
name = "typescript";
language-servers = [ "vtsls" ];
}
{
name = "nix";
language-servers = [ "nil" ];
auto-format = true;
formatter = {
command = "${pkgs.nixfmt-rfc-style}/bin/nixfmt";
args = [ "-" ];
};
}
{
name = "fish";
auto-format = true;
formatter.command = "${pkgs.fish}/bin/fish_indent";
}
{
name = "markdown";
language-servers = [ "ltex-ls" ];
auto-format = false;
formatter = {
command = "deno";
args = [
"--ext"
"md"
"-"
];
};
}
{
name = "git-commit";
language-servers = [ "ltex-ls" ];
}
];
};
};
}