-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
842 lines (797 loc) · 22.7 KB
/
init.lua
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local large_file_disable = function(buf)
local max_filesize = 1024 * 1024 -- 1 MB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end
require("lazy").setup({
{ "nvim-lua/plenary.nvim", lazy = true },
{ "kevinhwang91/promise-async", lazy = true },
{
"tpope/vim-commentary",
keys = "gc",
},
{
"neovim/nvim-lspconfig",
event = { "VeryLazy" },
cmd = { "LspInfo", "LspInstall", "LspUninstall" },
config = function()
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
capabilities.offsetEncoding = { "utf-16" }
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
lspconfig.clangd.setup({
capabilities = capabilities,
cmd = { "clangd", "--query-driver=/usr/bin/arm-none-eabi-g++" }
})
lspconfig.vimls.setup({ capabilities = capabilities })
lspconfig.cmake.setup({ capabilities = capabilities })
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
},
},
})
lspconfig.marksman.setup({ capabilities = capabilities })
lspconfig.ocamllsp.setup({ capabilities = capabilities, cmd = { "ocamllsp", "--fallback-read-dot-merlin" } })
lspconfig.texlab.setup({ capabilities = capabilities })
lspconfig.wgsl_analyzer.setup({ capabilities = capabilities })
lspconfig.bashls.setup({ capabilities = capabilities })
lspconfig.jsonls.setup({ capabilities = capabilities })
lspconfig.cssls.setup({ capabilities = capabilities })
lspconfig.html.setup({ capabilities = capabilities })
lspconfig.lemminx.setup({ capabilities = capabilities })
lspconfig.yamlls.setup({ capabilities = capabilities })
lspconfig.taplo.setup({ capabilities = capabilities })
lspconfig.dotls.setup({ capabilities = capabilities })
lspconfig.hls.setup({ capabilities = capabilities })
lspconfig.glsl_analyzer.setup({ capabilities = capabilities })
lspconfig.pylsp.setup({
capabilities = capabilities,
settings = {
pylsp = {
plugins = {
black = { enabled = true },
autopep8 = { enabled = false },
yapf = { enabled = false },
pylint = { enabled = true, executable = "pylint" },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
pylsp_mypy = { enabled = true },
jedi_completion = { fuzzy = true },
pyls_isort = { enabled = true },
}
}
}
})
lspconfig.ts_ls.setup({ capabilities = capabilities })
lspconfig.gdscript.setup({ capabilities = capabilities })
lspconfig.rust_analyzer.setup({
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
check = {
command = "clippy",
},
},
},
})
-- temporary fix for rust analyzer server cancelation request
for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do
local default_diagnostic_handler = vim.lsp.handlers[method]
vim.lsp.handlers[method] = function(err, result, context, config)
if err ~= nil and err.code == -32802 then
return
end
return default_diagnostic_handler(err, result, context, config)
end
end
vim.fn.sign_define("DiagnosticSignError", { text = "" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "" })
vim.fn.sign_define("DiagnosticSignInfo", { text = "" })
vim.fn.sign_define("DiagnosticSignHint", { text = "" })
vim.fn.sign_define("DiagnosticSignOk", { text = "" })
vim.diagnostic.config({ severity_sort = true, virtual_text = false })
-- vim.diagnostic.config({ severity_sort = true, virtual_text = { prefix = "" } })
local border = {
{ "╭", "FloatBorder" },
{ "─", "FloatBorder" },
{ "╮", "FloatBorder" },
{ "│", "FloatBorder" },
{ "╯", "FloatBorder" },
{ "─", "FloatBorder" },
{ "╰", "FloatBorder" },
{ "│", "FloatBorder" },
}
-- LSP settings (for overriding per client)
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with(vim.lsp.handlers.signature_help, { border = border })
vim.keymap.set("n", "<space>d", "<cmd>Trouble diagnostics<cr>")
vim.keymap.set("n", "<space>a", function() vim.lsp.buf.code_action() end)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "<space>h", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end)
-- switch source/header
vim.keymap.set("n", "g<space>", "<cmd>ClangdSwitchSourceHeader<cr>")
-- navigate soft line wraps
vim.keymap.set("n", "j", "gj")
vim.keymap.set("n", "k", "gk")
end,
},
{
"stevearc/dressing.nvim",
event = "VeryLazy",
opts = {},
},
{
"mfussenegger/nvim-jdtls",
ft = "java",
config = function()
local config = {
cmd = { "/usr/bin/jdtls" },
root_dir = vim.fs.dirname(vim.fs.find({ "build.gradle", "gradlew", ".git", "mvnw" },
{ upward = true })
[1]),
init_options = {
bundles = {
vim.fn.glob("/usr/share/java-debug/com.microsoft.java.debug.plugin.jar", 1),
},
},
}
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "java" },
callback = function()
require("jdtls").start_or_attach(config)
end,
})
end,
},
{
"smjonas/inc-rename.nvim",
keys = "<space>r",
config = function()
require("inc_rename").setup({})
vim.keymap.set("n", "<space>r", ":IncRename ")
end,
},
{
"nvim-treesitter/nvim-treesitter",
event = "BufRead",
build = ":TSUpdate",
config = function()
require("nvim-treesitter.configs").setup({
auto_install = true,
highlight = {
enable = true,
disable = function(_, buf)
return large_file_disable(buf)
end,
},
-- indent = {
-- enable = true,
-- },
endwise = {
enable = true,
},
})
require('nvim-ts-autotag').setup({
opts = {
enable_close = true,
enable_rename = true,
enable_close_on_slash = false
},
})
end,
dependencies = {
"RRethy/nvim-treesitter-endwise",
"windwp/nvim-ts-autotag",
},
},
{
"stevearc/conform.nvim",
event = "BufWritePre",
opts = {
notify_on_error = false,
formatters_by_ft = {
javascript = { "deno_fmt" },
javascriptreact = { "deno_fmt" },
json = { "deno_fmt" },
jsonc = { "deno_fmt" },
typescript = { "deno_fmt" },
html = { "prettierd" },
css = { "prettierd" },
scss = { "prettierd" },
vue = { "prettierd" },
markdown = { "prettierd" },
yaml = { "deno_fmt" },
rust = { "rustfmt" },
c = { "clang_format" },
cpp = { "clang_format" },
lua = { "stylua" },
ocaml = { "ocamlformat" },
haskell = { "ormolu" },
python = { "black", "isort" },
tex = { "latexindent" },
_ = { "trim_whitespace" },
},
format_on_save = function(bufnr)
if not vim.api.nvim_buf_get_option(bufnr, "modified") then
return
end
return { timeout_ms = 10000, lsp_fallback = true }
end,
formatters = {
["ocamlformat"] = {
command = "ocamlformat",
args = {
"--doc-comments=before",
"--wrap-comments",
"--parse-docstrings",
"--name",
"$FILENAME",
"-",
},
},
},
},
},
{
"nvim-telescope/telescope.nvim",
lazy = true,
keys = { "<space>f", "<space>/" },
cmd = { "Telescope" },
opts = {
pickers = {
find_files = {
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/" },
},
},
},
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
vim.keymap.set("n", "<space>f", "<cmd>Telescope fd<cr>")
vim.keymap.set("n", "<space>/", "<cmd>Telescope live_grep<cr>")
end
},
{
"hrsh7th/nvim-cmp",
lazy = true,
event = { "InsertEnter", "CmdlineEnter" },
config = function()
local cmp = require("cmp")
local lspkind = require("lspkind")
local snippy = require("snippy")
-- require("copilot_cmp").setup()
lspkind.init({
symbol_map = {
Copilot = "",
},
})
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") ==
nil
end
local fast_cmp_visible = function()
if not (cmp.core.view and cmp.core.view.custom_entries_view) then
return false
end
return cmp.core.view.custom_entries_view:visible()
end
cmp.setup({
snippet = {
expand = function(args)
snippy.expand_snippet(args.body)
end,
},
completion = {
completeopt = "menu,menuone,noinsert",
},
-- matching = {
-- disallow_fuzzy_matching = true,
-- disallow_fullfuzzy_matching = true,
-- disallow_partial_fuzzy_matching = true,
-- disallow_partial_matching = true,
-- disallow_prefix_unmatching = false,
-- },
mapping = cmp.mapping.preset.insert({
["<cr>"] = cmp.mapping(function(fallback)
local entry = cmp.core.view:get_selected_entry()
if fast_cmp_visible() and not (entry and entry.source.name == "nvim_lsp_signature_help") then
cmp.confirm({ select = true })
cmp.close()
elseif snippy.can_expand_or_advance() then
snippy.expand_or_advance()
else
-- expand tags on enter
local col = vim.api.nvim_win_get_cursor(0)[2]
local line_text = vim.api.nvim_get_current_line()
if col > 0 and col <= #line_text then
local c0 = line_text:sub(col, col)
local c1 = line_text:sub(col + 1, col + 1)
if c0 == ">" and c1 == "<" then
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(
"<cr><esc>O<tab>", true, true, true),
'n',
true)
return
-- elseif c0 == "{" then
-- if c1 == "}" then
-- vim.api.nvim_feedkeys(
-- vim.api.nvim_replace_termcodes(
-- "<cr><esc>O", true, true, true),
-- 'n',
-- true)
-- return
-- else
-- vim.api.nvim_feedkeys(
-- vim.api.nvim_replace_termcodes(
-- "<cr>}<esc>O", true, true, true),
-- 'n',
-- true)
-- return
-- end
-- elseif c0 == "[" then
-- if c1 == "]" then
-- vim.api.nvim_feedkeys(
-- vim.api.nvim_replace_termcodes(
-- "<cr><esc>O", true, true, true),
-- 'n',
-- true)
-- return
-- else
-- vim.api.nvim_feedkeys(
-- vim.api.nvim_replace_termcodes(
-- "<cr>]<esc>O", true, true, true),
-- 'n',
-- true)
-- return
-- end
end
end
fallback()
end
end),
["<tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<s-tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
elseif snippy.can_jump(-1) then
snippy.previous()
else
fallback()
end
end, { "i", "s" }),
["<esc>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.abort()
end
fallback()
end, { "i", "s" })
}),
sources = cmp.config.sources({
-- { name = "copilot" },
{ name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" },
{ name = "path" },
}, {}),
formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text',
maxwidth = 50,
ellipsis_char = '...',
show_labelDetails = true,
})
},
})
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "cmdline" },
}, {}),
preselect = cmp.PreselectMode.None,
completion = { completeopt = "menu,menuone,noselect" },
})
end,
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-cmdline",
"onsails/lspkind.nvim",
"hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lsp-signature-help",
"dcampos/nvim-snippy",
-- "zbirenbaum/copilot-cmp",
},
},
{
"kylechui/nvim-surround",
keys = { "ys", "cs", "ds" },
config = function()
require("nvim-surround").setup({})
end,
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
config = function()
local npairs = require('nvim-autopairs')
local rule = require('nvim-autopairs.rule')
local cond = require('nvim-autopairs.conds')
npairs.setup({})
-- npairs.add_rule(rule("$$", "$$", "tex"))
-- npairs.add_rules({
-- rule("\\start(%w*) $", "")
-- :replace_endpair(function(opts)
-- local beforeText = string.sub(opts.line, 0, opts.col)
-- local _, _, match = beforeText:find("\\start(%w*)")
-- if match and #match > 0 then
-- return " \\stop" .. match
-- end
-- return ''
-- end)
-- :with_move(cond.none())
-- :use_key("<space>")
-- :use_regex(true)
-- })
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp = require("cmp")
cmp.event:on(
"confirm_done",
cmp_autopairs.on_confirm_done()
)
end
},
{
"lewis6991/gitsigns.nvim",
event = "VeryLazy",
config = function()
require("gitsigns").setup({
signs = {
add = { text = '│' },
change = { text = '│' },
},
signs_staged = {
add = { text = '│' },
change = { text = '│' },
},
})
vim.keymap.set("n", "]g", "<cmd>Gitsigns next_hunk<cr><cmd>Gitsigns preview_hunk_inline<cr>")
vim.keymap.set("n", "[g", "<cmd>Gitsigns prev_hunk<cr><cmd>Gitsigns preview_hunk_inline<cr>")
vim.keymap.set("n", "ghs", "<cmd>Gitsigns stage_hunk<cr>")
vim.keymap.set("n", "ghu", "<cmd>Gitsigns undo_stage_hunk<cr>")
vim.keymap.set("n", "ghr", "<cmd>Gitsigns reset_hunk<cr>")
end,
},
{
"tpope/vim-fugitive",
lazy = true,
keys = { "<space>g", "<space>G", "<space>b" },
cmd = { "Git", "Gsplit", "Gvsplit", "Gdiffsplit", "Gvdiffsplit" },
config = function()
vim.keymap.set("n", "<space>g", "<cmd>Git<cr><cmd>wincmd L<cr>")
vim.keymap.set("n", "<space>G",
"<cmd>Gvdiffsplit!<cr><cmd>set foldcolumn=0<cr><cmd>wincmd h<cr><cmd>set foldcolumn=0<cr>")
vim.keymap.set("n", "<space>b", "<cmd>Gitsigns blame<cr>")
end,
},
{
"tpope/vim-sleuth",
event = "VeryLazy",
},
{
"rmagatti/goto-preview",
keys = { "gp", "gP" },
config = function()
local goto_preview = require("goto-preview")
goto_preview.setup({})
vim.keymap.set("n", "gpd", goto_preview.goto_preview_definition)
vim.keymap.set("n", "gpr", goto_preview.goto_preview_references)
vim.keymap.set("n", "gpi", goto_preview.goto_preview_implementation)
vim.keymap.set("n", "gpy", goto_preview.goto_preview_type_definition)
vim.keymap.set("n", "gP", goto_preview.close_all_win)
end,
},
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" },
build = "cd app && yarn install",
init = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
config = function()
vim.g.mkdp_theme = "light"
vim.g.mkdp_preview_options = {
-- disable_sync_scroll = 1,
}
end
},
{
"saecki/crates.nvim",
event = "BufRead Cargo.toml",
config = function()
require("crates").setup()
end,
},
{
"rhysd/conflict-marker.vim",
event = "VeryLazy",
},
-- {
-- "zbirenbaum/copilot.lua",
-- cmd = "Copilot",
-- event = "InsertEnter",
-- config = function()
-- require("copilot").setup({
-- panel = { enabled = false },
-- suggestion = { enabled = false },
-- filetypes = {
-- tex = false,
-- }
-- })
-- end,
-- },
{
"RRethy/vim-illuminate",
event = "VeryLazy",
config = function()
require("illuminate").configure({
delay = 500,
providers = {
"lsp",
"treesitter",
}
})
end,
},
{
"nvim-neo-tree/neo-tree.nvim",
keys = "-",
cmd = "Neotree",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
config = function()
require("neo-tree").setup({
close_if_last_window = true,
filesystem = {
window = {
mappings = {
["O"] = "system_open",
["/"] = "noop",
["esc"] = "noop",
},
width = 30,
},
default_component_configs = {
filesystem = {
bind_to_cwd = true,
follow_current_file = {
enabled = true,
},
},
buffers = {
follow_current_file = {
enabled = true,
},
},
},
},
commands = {
system_open = function(state)
local node = state.tree:get_node()
local path = node:get_id()
vim.fn.jobstart({ "xdg-open", path }, { detach = true })
end,
},
})
vim.keymap.set("n", "-", "<cmd>Neotree<cr>")
vim.keymap.set("n", "<space>-", "<cmd>Neotree reveal_force_cwd<cr>")
end
},
{
"akinsho/toggleterm.nvim",
keys = "<c-cr>",
config = function()
require("toggleterm").setup({
highlights = {
["Normal"] = { link = "Terminal" },
["NormalFloat"] = { link = "Terminal" },
},
shade_terminals = false,
insert_mappings = false,
terminal_mappings = false,
start_in_insert = false,
open_mapping = "<c-cr>",
direction = "tab",
})
end
},
{
"folke/trouble.nvim",
event = "LspAttach",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("trouble").setup({
auto_close = true,
auto_jump = true,
focus = true,
warn_no_results = false,
multiline = false,
win = {
size = 0.3,
},
throttle = {
refresh = 0,
update = 0,
render = 0,
follow = 0,
preview = { ms = 0, debounce = false },
},
})
vim.keymap.set("n", "gd", "<cmd>Trouble lsp_definitions<cr>")
vim.keymap.set("n", "gy", "<cmd>Trouble lsp_type_definitions<cr>")
vim.keymap.set("n", "gr", "<cmd>Trouble lsp_references<cr>")
vim.keymap.set("n", "gi", "<cmd>Trouble lsp_implementations<cr>")
vim.keymap.set("n", "go", "<cmd>Trouble lsp_incoming_calls<cr>")
vim.keymap.set("n", "gs", "<cmd>Trouble symbols toggle pinned=true win.relative=win win.position=right<cr>")
end
},
{
"nanotee/zoxide.vim",
cmd = "Z",
},
{
"ThePrimeagen/harpoon",
keys = "<space>",
branch = "harpoon2",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local harpoon = require("harpoon")
harpoon:setup()
vim.keymap.set("n", "<space>`", function() harpoon:list():add() end)
vim.keymap.set("n", "<space><space>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
vim.keymap.set("n", "<space>1", function() harpoon:list():select(1) end)
vim.keymap.set("n", "<space>2", function() harpoon:list():select(2) end)
vim.keymap.set("n", "<space>3", function() harpoon:list():select(3) end)
vim.keymap.set("n", "<space>4", function() harpoon:list():select(4) end)
vim.keymap.set("n", "<space>5", function() harpoon:list():select(5) end)
vim.keymap.set("n", "<space>6", function() harpoon:list():select(6) end)
vim.keymap.set("n", "<space>7", function() harpoon:list():select(7) end)
vim.keymap.set("n", "<space>8", function() harpoon:list():select(8) end)
vim.keymap.set("n", "<space>9", function() harpoon:list():select(9) end)
end
},
})
-- set help window to vertical split
vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "help" }, command = "wincmd L" })
-- latex
vim.api.nvim_create_user_command("LatexCompile", function()
local texpath = vim.fn.expand("%")
vim.cmd("!tectonic -Z continue-on-errors " .. texpath)
end, {})
vim.api.nvim_create_user_command("LatexCompileBackground", function()
local texpath = vim.fn.expand("%")
vim.cmd("silent !tmux new -d \"tectonic -Z continue-on-errors " .. texpath .. "\"")
end, {})
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = { "*.tex" },
command = "LatexCompileBackground",
})
-- config quick edit
vim.api.nvim_create_user_command("Config", function()
vim.cmd("e " .. debug.getinfo(1).source:sub(2))
end, {})
-- disable auto comment
vim.cmd("autocmd BufNewFile,BufRead * setlocal formatoptions=qnlj")
-- keymaps
do
-- easy exit terminal mode
vim.keymap.set("t", "<c-a>", "<c-\\><c-n>")
-- navigation
vim.keymap.set("n", "<c-h>", "<c-w><c-h>")
vim.keymap.set("n", "<c-j>", "<c-w><c-j>")
vim.keymap.set("n", "<c-k>", "<c-w><c-k>")
vim.keymap.set("n", "<c-l>", "<c-w><c-l>")
vim.keymap.set("n", "<c-t>", "<cmd>tabnew<cr>")
vim.keymap.set("n", "L", "<cmd>tabnext<cr>")
vim.keymap.set("n", "H", "<cmd>tabprev<cr>")
vim.keymap.set("n", "<c-s>", function()
vim.cmd("wincmd v")
vim.cmd("wincmd l")
end)
vim.keymap.set("n", "<c-n>", function()
vim.cmd("new")
vim.cmd("wincmd L")
end)
vim.keymap.set("n", "<a-h>", "<c-w><c-<>")
vim.keymap.set("n", "<a-j>", "<c-w><c-+>")
vim.keymap.set("n", "<a-k>", "<c-w><c-->")
vim.keymap.set("n", "<a-l>", "<c-w><c->>")
-- clear highlighting
vim.keymap.set("n", "<esc>", "<cmd>noh<cr>")
end
-- startup commands
vim.opt.compatible = false
vim.opt.swapfile = false
vim.opt.signcolumn = "yes"
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.linebreak = true
vim.opt.shell = "fish"
vim.opt.textwidth = 80
vim.opt.scrolloff = 5
vim.opt.clipboard = "unnamedplus"
vim.opt.shortmess:append("I")
vim.opt.pumheight = 10
vim.opt.termguicolors = true
vim.opt.mousescroll = "hor:0,ver:2"
vim.opt.conceallevel = 0
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.wrap = false
vim.opt.smartindent = true
vim.opt.guifont = "CommitMono:h9.5"
-- spell for markdown files
-- Set spell check only for markdown files
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.opt_local.spell = true
end,
})
-- colorscheme
vim.cmd.colorscheme("lesswarm")
-- neovide config
if vim.g.neovide then
local default_scale_factor = 1
vim.g.neovide_scale_factor = default_scale_factor
vim.keymap.set("n", "<c-=>", function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 1.1
vim.cmd("redraw!")
end)
vim.keymap.set("n", "<c-->", function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor / 1.1
vim.cmd("redraw!")
end)
vim.keymap.set("n", "<c-0>", function()
vim.g.neovide_scale_factor = default_scale_factor
vim.cmd("redraw!")
end)
end