-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
1062 lines (888 loc) · 34 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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- {{{ Mandatory editor settings
if vim.fn.has("win32") == 1 then
vim.g.configForWork = 1
vim.g.python3_host_prog = 'C:/ProgramData/chocolatey/bin/python3.12.EXE'
vim.g.python_host_prog = 'C:/Python27/python.exe'
vim.g.loaded_perl_provider = 0
vim.g.loaded_node_provider = 0
vim.g.loaded_ruby_provider = 0
end
--}}}
-- {{{ Plugins func
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup(
{
-- {{{ Mini.nvim
{
"echasnovski/mini.nvim",
init = function()
require('mini.basics').setup()
require('mini.ai').setup()
require('mini.align').setup({
mappings = {
start = '<Enter>',
start_with_preview = 'gA',
}
})
require('mini.comment').setup()
require('mini.jump').setup()
-- TODO: seems like replacement to MRU - not really, it's project based
require('mini.visits').setup()
require('mini.pick').setup()
require('mini.extra').setup()
-- TODO:maye do it later
--require('mini.completion').setup()
require('mini.pairs').setup()
-- gS, go split
require('mini.splitjoin').setup()
-- {{{ mini.statusline
require('mini.statusline').setup(
{
-- Content of statusline as functions which return statusline string. See
-- `:h statusline` and code of default contents (used instead of `nil`).
content = {
-- Content for active window
active = function()
local mode, mode_hl = MiniStatusline.section_mode { trunc_width = 120 }
local git = MiniStatusline.section_git { trunc_width = 75 }
local diagnostics = MiniStatusline.section_diagnostics { trunc_width = 75 }
local filename = MiniStatusline.section_filename { trunc_width = 140 }
local fileinfo = MiniStatusline.section_fileinfo { trunc_width = 120 }
local location = MiniStatusline.section_location { trunc_width = 75 }
local search = MiniStatusline.section_searchcount { trunc_width = 75 }
-- vim.opt.laststatus = 3
return MiniStatusline.combine_groups {
{ hl = mode_hl },
{ strings = { mode } },
{ hl = 'MiniStatuslineInactive', strings = { git, diagnostics, search } },
'%=', -- Start center alignment
'%<', -- Mark general truncate point
{ strings = { filename } },
'%=', -- start right alignment
{ hl = 'MiniStatuslineInactive', strings = { fileinfo } },
{ strings = { location } },
}
end,
inactive = function() end,
},
set_vim_settings = false,
})
-- }}}
-- {{{ mini.surround
require('mini.surround').setup({
mappings = {
add = 'S', -- Add surrounding in Normal and Visual modes
delete = 'ds', -- Delete surrounding
replace = 'cs', -- Replace surrounding
update_n_lines = 'sn', -- Update `n_lines`
suffix_last = 'l', -- Suffix to search with "prev" method
suffix_next = 'n', -- Suffix to search with "next" method
},
n_lines = 120,
})
-- }}}
require('mini.diff').setup()
vim.keymap.set('n', '<leader>go', ':lua MiniDiff.toggle_overlay()<CR>', { desc = 'Toggle Diff Overlay' })
-- TODO: replace tabby with this one after removing the buffers from the tab
-- require('mini.tabline').setup({})
vim.o.showtabline = 2
vim.opt.sessionoptions = 'curdir,folds,globals,help,tabpages,terminal,winsize'
require('mini.splitjoin').setup()
-- {{{ Mini.clues
local miniclue = require('mini.clue')
miniclue.setup({
triggers = {
-- Leader triggers
{ mode = 'n', keys = '<Leader>' },
{ mode = 'x', keys = '<Leader>' },
-- Built-in completion
{ mode = 'i', keys = '<C-x>' },
-- `g` key
{ mode = 'n', keys = 'g' },
{ mode = 'x', keys = 'g' },
-- Marks
{ mode = 'n', keys = "'" },
{ mode = 'n', keys = '`' },
{ mode = 'x', keys = "'" },
{ mode = 'x', keys = '`' },
-- Registers
{ mode = 'n', keys = '"' },
{ mode = 'x', keys = '"' },
{ mode = 'i', keys = '<C-r>' },
{ mode = 'c', keys = '<C-r>' },
-- Window commands
{ mode = 'n', keys = '<C-w>' },
-- `z` key
{ mode = 'n', keys = 'z' },
{ mode = 'x', keys = 'z' },
},
clues = {
-- Enhance this by adding descriptions for <Leader> mapping groups
miniclue.gen_clues.builtin_completion(),
miniclue.gen_clues.g(),
miniclue.gen_clues.marks(),
miniclue.gen_clues.registers(),
miniclue.gen_clues.windows(),
miniclue.gen_clues.z(),
},
})
-- }}}
require('mini.bracketed').setup()
require('mini.git').setup()
-- {{{ mini.hipatterns
local hipatterns = require('mini.hipatterns')
hipatterns.setup({
highlighters = {
fixme = { pattern = '%f[%w]()FIXME:()%f[%W]', group = 'MiniHipatternsFixme' },
hack = { pattern = '%f[%w]()HACK:()%f[%W]', group = 'MiniHipatternsHack' },
error = { pattern = '%f[%w]()ERROR:()%f[%W]', group = 'MiniHipatternsHack' },
warn = { pattern = '%f[%w]()WARN:()%f[%W]', group = 'MiniHipatternsHack' },
todo = { pattern = '%f[%w]()TODO:()%f[%W]', group = 'MiniHipatternsTodo' },
note = { pattern = '%f[%w]()NOTE:()%f[%W]', group = 'MiniHipatternsNote' },
hex_color = hipatterns.gen_highlighter.hex_color(),
},
})
-- }}}
require('mini.notify').setup({
lsp_progress = {
enable = false,
},
})
require('mini.operators').setup()
require('mini.trailspace').setup()
end, -- end of mini
},
-- }}}
-- {{{ Mark:
{
"inkarkat/vim-mark",
event = "VeryLazy",
dependencies = {
"inkarkat/vim-ingo-library"
},
init = function()
vim.g.mw_no_mappings = 1
vim.g.mwDefaultHighlightingPalette = 'extended'
end,
},
-- }}}
-- {{{ RipGrep plugins
{
"wincent/ferret",
dependencies = {
"yssl/QFEnter",
},
init = function()
vim.g.FerretAutojump = 0
vim.g.FerretHlsearch = 1
vim.g.FerretMap = 0
vim.g.FerretQFCommands = 0
vim.g.FerretExecutableArguments = { rg = '-H -S --sort path --column --line-number --no-heading --ignore-file '..vim.env.HOME..'/ignore' }
vim.g.qfenter_keymap = {
open = { '<CR>' },
vopen = { '<C-v>' },
hopen = { '<C-s>' },
topen = { '<C-t>' },
}
-- keep the quickfix window open
vim.cmd('autocmd FileType qf nnoremap <buffer> <C-t> <C-w><CR><C-w>T')
end
},
{ "Olical/vim-enmasse", cmd = "EnMasse" },
--}}}
-- {{{ Tabline
{
"nanozuki/tabby.nvim",
enabled = true,
lazy = false,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
vim.o.showtabline = 2
vim.opt.sessionoptions = 'curdir,folds,globals,help,tabpages,terminal,winsize'
local theme = {
fill = 'TabLineFill',
head = 'TabLine',
current_tab = { fg = '#F8FBF6', bg = '#887a95', style = 'italic' },
tab = 'TabLine',
win = 'TabLine',
tail = 'TabLine',
}
require('tabby.tabline').set(function(line)
return {
{
line.sep(' ', theme.head, theme.fill),
},
line.tabs().foreach(function(tab)
local hl = tab.is_current() and theme.current_tab or theme.tab
return {
line.sep(' ', hl, theme.fill),
tab.is_current() and '» ' or ' ',
tab.number(),
tab.name(),
tab.close_btn('x'), -- show a close button
line.sep(' ', hl, theme.fill),
hl = hl,
margin = ' ',
}
end),
line.spacer(),
line.wins_in_tab(line.api.get_current_tab()).foreach(function(win)
return {
line.sep(' ', theme.win, theme.fill),
win.is_current() and '»' or ' ',
win.buf_name(),
line.sep(' ', theme.win, theme.fill),
hl = theme.win,
margin = ' ',
}
end),
{
line.sep(' ', theme.tail, theme.fill),
},
hl = theme.fill,
}
end)
end,
},
-- }}}
-- {{{ Dial.nvim
{
"monaqa/dial.nvim",
event = "VeryLazy",
config = function()
local augend = require("dial.augend")
require("dial.config").augends:register_group{
default = {
augend.constant.alias.bool,
augend.semver.alias.semver,
augend.integer.alias.decimal,
augend.integer.alias.hex,
augend.date.alias["%Y/%m/%d"],
augend.constant.new{ elements = {"true", "false"} },
augend.constant.new{ elements = {"TRUE", "FALSE"} },
augend.constant.new{ elements = {"E_OK", "E_NOT_OK"} },
augend.constant.new{ elements = {"DCM_INITIAL", "DCM_CANCEL", "DCM_E_PENDING", "DCM_E_FORCE_RCRRP"} },
},
}
vim.keymap.set("n", "<C-a>", function() require("dial.map").manipulate("increment", "normal") end)
vim.keymap.set("n", "<C-x>", function() require("dial.map").manipulate("decrement", "normal") end)
vim.keymap.set("n", "g<C-a>", function() require("dial.map").manipulate("increment", "gnormal") end)
vim.keymap.set("n", "g<C-x>", function() require("dial.map").manipulate("decrement", "gnormal") end)
vim.keymap.set("v", "<C-a>", function() require("dial.map").manipulate("increment", "visual") end)
vim.keymap.set("v", "<C-x>", function() require("dial.map").manipulate("decrement", "visual") end)
vim.keymap.set("v", "g<C-a>", function() require("dial.map").manipulate("increment", "gvisual") end)
vim.keymap.set("v", "g<C-x>", function() require("dial.map").manipulate("decrement", "gvisual") end)
end,
},
-- }}}
-- {{{ Marks.nvim
{
"chentoast/marks.nvim",
event = "VeryLazy",
init = function()
require'marks'.setup({})
end,
},
--}}}
{ "AndrewRadev/linediff.vim", cmd = "Linediff" },
{ "mbbill/undotree" },
{ "bfrg/vim-cpp-modern" },
-- {{{ Treesitter
{
"nvim-treesitter/nvim-treesitter",
version = false,
build = ":TSUpdate",
event = { "VeryLazy" },
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
init = function(plugin)
require("lazy.core.loader").add_to_rtp(plugin)
require("nvim-treesitter.query_predicates")
end,
cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" },
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "c", "lua" },
auto_install = true,
highlight = { enable = true },
})
end,
},
-- }}}
-- {{{ Vaffle
{
"cocopon/vaffle.vim",
init = function()
local function customize_vaffle_mappings()
vim.api.nvim_buf_set_keymap(0, 'n', 'U', '<Plug>(vaffle-open-root)', { noremap = false, silent = true })
vim.api.nvim_buf_set_keymap(0, 'n', 'u', '<Plug>(vaffle-open-parent)', { noremap = false, silent = true })
end
vim.api.nvim_create_augroup('vimrc_vaffle', { clear = true })
vim.api.nvim_create_autocmd('FileType', { group = 'vimrc_vaffle', pattern = 'vaffle', callback = customize_vaffle_mappings })
end
},
-- }}}
{ "nlknguyen/papercolor-theme", priority = 1000 },
{ "rakr/vim-one", priority = 1000 },
{
"dstein64/vim-startuptime",
cmd = "StartupTime",
init = function()
vim.g.startuptime_tries = 10
end,
},
{
"ctrlpvim/ctrlp.vim",
init = function()
vim.g.ctrlp_max_history = 4000
vim.g.ctrlp_user_command = 'rg %s --files --color=never --glob ""'
vim.g.ctrlp_use_caching = 0
end,
},
-- {{{ indent-blankline.nvim
{
"lukas-reineke/indent-blankline.nvim",
event = "VeryLazy",
opts = {
indent = {
char = "│",
tab_char = "│",
},
scope = { show_start = false, show_end = false },
exclude = {
filetypes = {
"help",
"alpha",
"dashboard",
"neo-tree",
"Trouble",
"trouble",
"lazy",
"mason",
"notify",
"toggleterm",
"lazyterm",
},
},
},
main = "ibl",
},
-- }}}
{
"folke/persistence.nvim",
event = "BufReadPre",
opts = { options = vim.opt.sessionoptions:get() },
keys = {
{ "<leader>qs", function() require("persistence").load() end, desc = "Restore Session" },
{ "<leader>ql", function() require("persistence").load({ last = true }) end, desc = "Restore Last Session" },
{ "<leader>qd", function() require("persistence").stop() end, desc = "Don't Save Current Session" },
},
},
{
-- zoom plugin
"tenxsoydev/size-matters.nvim",
init = function()
require("size-matters").setup()
end,
},
{
-- TODO: check this one, seems interesting
"LeonHeidelbach/trailblazer.nvim",
enabled=false,
init = function()
require("trailblazer").setup({})
end,
},
{ "folke/neodev.nvim", opts = {} },
-- {{{ nvim-cmp
{
-- Autocompletion
'hrsh7th/nvim-cmp',
event = "InsertEnter",
dependencies = {
-- Adds LSP completion capabilities
'hrsh7th/cmp-nvim-lsp',
-- other sources
'hrsh7th/cmp-path',
'hrsh7th/cmp-buffer',
},
config = function()
local cmp = require 'cmp'
local cmp_kinds = { Text = ' ', Method = ' ', Function = ' ', Constructor = ' ',
Field = ' ', Variable = ' ', Class = ' ', Interface = ' ', Module = ' ', Property = ' ',
Unit = ' ', Value = ' ', Enum = ' ', Keyword = ' ', Color = ' ',
File = ' ', Reference = ' ', Folder = ' ', EnumMember = ' ', Constant = ' ', Struct = ' ',
Event = ' ', Operator = ' ', TypeParameter = ' ' }
local border_opts = { border = "rounded", winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None" }
cmp.setup {
formatting = {
fields = { 'abbr', 'kind' },
format = function(_, item) item.kind = (cmp_kinds[item.kind] or '') .. item.kind return item end,
},
window = {
completion = cmp.config.window.bordered(border_opts),
documentation = cmp.config.window.bordered(border_opts),
},
experimental = { ghost_text = true },
mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Replace }),
['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Replace }),
['<C-e>'] = cmp.mapping.scroll_docs(-4),
['<C-y>'] = cmp.mapping.scroll_docs(4),
['<CR>'] = function(fallback) if cmp.visible() and cmp.get_active_entry() then cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) else fallback() end end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
},
}
end,
},
-- }}}
-- {{{ nvim-lspconfig
{
-- LSP Configuration & Plugins
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs to stdpath for neovim
{ 'williamboman/mason.nvim', config = true, event = "VeryLazy" },
{ 'williamboman/mason-lspconfig.nvim', event = "VeryLazy", },
-- Additional lua configuration, makes nvim tinkering amazing!
'folke/neodev.nvim',
},
config = function()
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
local nmap = function(keys, func, desc)
if desc then desc = ' ' .. desc end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>k', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<leader>K', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' })
-- Range formatting via motion.
-- https://github.com/neovim/neovim/issues/14680
local operator_register = function(name, fn)
_G[name] = function(type)
if type == nil then vim.opt.opfunc = 'v:lua.' .. name return 'g@' -- calls back to this function
end
-- boilerplate save, see :help g@
local sel_save = vim.opt.selection
local reg_save = vim.fn.getreginfo('"')
local cb_save = vim.opt.clipboard
local visual_marks_save = { vim.fn.getpos("'<"), vim.fn.getpos("'>") }
-- boilerplate setup
vim.opt.clipboard = ''
vim.opt.selection = 'inclusive'
local status, err = pcall(fn, type)
-- boilerplate restore
vim.fn.setreg('"', reg_save)
vim.fn.setpos("'<", visual_marks_save[0])
vim.fn.setpos("'>", visual_marks_save[1])
vim.opt.clipboard = cb_save
vim.opt.selection = sel_save
if not status then
error(err)
end
end
end
operator_register('op_format_code', function(type)
vim.lsp.buf.format {
range = {
['start'] = vim.api.nvim_buf_get_mark(0, '['),
['end'] = vim.api.nvim_buf_get_mark(0, ']'),
},
}
end)
end
-- Enable the following language servers
local servers = {
-- clangd = {
-- cmd = { 'clangd', '--background-index' }, -- Adjust the command as needed
-- filetypes = { 'c', 'cpp', 'c.m4', 'h.m4' }, -- Specify the filetypes you're working with
-- root_dir = function(fname)
-- -- Customize this function to return the root directory for your project
-- return vim.fs.root(vim.fn.expand('%:p'), root_patterns) or vim.fn.getcwd()
-- end,
-- },
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
lua_ls = {
Lua = {
runtime = { version = 'LuaJIT' },
diagnostics = { globals = { 'vim', 'require' } },
workspace = { checkThirdParty = false, library = vim.api.nvim_get_runtime_file("", true) },
telemetry = { enable = false },
},
},
}
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Ensure the servers above are installed
local mason_lspconfig = require('mason-lspconfig')
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end
}
end
},
-- }}}
{
"levouh/tint.nvim",
init = function()
require("tint").setup({
tint = -15, -- Darken colors, use a positive value to brighten
saturation = 0.6, -- Saturation to preserve
})
end,
},
}
)
-- }}}
-- {{{ Mappings
local map = vim.api.nvim_set_keymap
local mapf = vim.keymap.set
local opts = { noremap = true, silent = true }
map('n', '<Leader>e', ':lua PrepRgCommand()<CR>', { noremap = true, silent = true, desc = "Call ripgrep in the root directory" })
map('n', '<Leader>r', ':lua PrepRgCommand(\'cword\')<CR>', { noremap = true, silent = true, desc = "Call ripgrep with <cword> in the root directory" })
mapf("n", "<leader>n", function() MiniPick.builtin.files({}, { source = { cwd = GetRootDir(), }, }) end, { desc = "Find files in project" })
-- Synchronized scroll
map('n', '<Leader>sz', ':set scb!<CR>', { noremap = true, silent = true, desc = "Sync scroll between windows" })
-- Delete inactive buffers
map('n', '<Leader>db', ':call DeleteInactiveBufs()<CR>', { noremap = true, silent = true, desc = "Delette inactive buffers" })
map('n', '<Leader>dd', ':diffthis<CR>', { noremap = true, silent = true, desc = "Diff this file" })
map('n', '<Leader>do', ':diffoff<CR>', { noremap = true, silent = true, desc = "Diff off" })
map('n', '<Leader>dp', ':diffput<CR>', { noremap = true, silent = true, desc = "Diff put" })
map('n', '<Leader>dg', ':diffget<CR>', { noremap = true, silent = true, desc = "Diff get" })
map('n', '<Leader>du', ':diffupdate<CR>', { noremap = true, silent = true, desc = "Diff update" })
map('v', '<Leader>ld', ':Linediff<CR>', { noremap = true, silent = true, desc = "Line diff" })
map('n', '<Leader>m', ':CtrlPMRUFiles<CR>', { noremap = true, silent = true, desc = "Browse MRU files" })
map('n', '<Leader>st', ':lua MiniTrailspace.trim()<CR>', { noremap = true, silent = true, desc = "Trim trailing spaces" })
map('n', '<Leader>sw', ':set wrap!<CR>', { noremap = true, silent = true, desc = "Toggle wrap" })
map('n', '<Leader>tc', ':tabclose<CR>', { noremap = true, silent = true, desc = "Tab close" })
map('n', '<Leader>tn', ':tabnew<CR>', { noremap = true, silent = true, desc = "Tab new" })
map('n', '<Leader>/', ':nohlsearch<CR>', { noremap = true, silent = true, desc = "Clear search term" })
map('n', '<Leader>c', ':call ToggleColorColumn()<CR>', { noremap = true, silent = true, desc = "Toggle 100 collumn marker" })
map('n', 'z=', ':Pick spellsuggest<CR>', { noremap = true, silent = true, desc = "Pick spelling suggestion" })
map('n', '<leader>ov', ':exe ":silent !code %"<CR>', { noremap = true, silent = true, desc = "Open in VS-Code" })
-- Remap jj to <Esc> in insert mode
map('i', 'jj', '<Esc>', {noremap = true})
-- Paste from clipboard in insert mode
map('i', '<S-Insert>', '<C-R>+', opts)
mapf('c', '<C-v>', '<C-R>+' )
-- Change into the black hole register to not clobber the last yank
-- map('n', 'c', '"_c', opts)
-- Select last visual block
map('n', 'gp', '`[v`]', opts)
-- Find file under cursor in the same window
map('n', 'gf', 'gF', opts)
-- highlight selected word
map('v', '//', 'y/\\V<C-R>"<CR>', { noremap = true, silent = true })
-- Navigate 5x faster when holding down Ctrl
map('n', '<C-j>', '5j', { noremap = true })
map('n', '<C-k>', '5k', { noremap = true })
map('n', '<C-h>', '5h', { noremap = true })
map('n', '<C-l>', '5l', { noremap = true })
map('v', '<C-j>', '5j', { noremap = true })
map('v', '<C-k>', '5k', { noremap = true })
map('v', '<C-h>', '5h', { noremap = true })
map('v', '<C-l>', '5l', { noremap = true })
-- Window navigation
map('n', '<A-k>', ':wincmd k<CR>', opts)
map('n', '<A-j>', ':wincmd j<CR>', opts)
map('n', '<A-h>', ':wincmd h<CR>', opts)
map('n', '<A-l>', ':wincmd l<CR>', opts)
map('t', '<A-k>', '<C-\\><C-N>:wincmd k<CR>', opts)
map('t', '<A-j>', '<C-\\><C-N>:wincmd j<CR>', opts)
map('t', '<A-h>', '<C-\\><C-N>:wincmd h<CR>', opts)
map('t', '<A-l>', '<C-\\><C-N>:wincmd l<CR>', opts)
-- Resize windows
map('n', '<S-k>', ':resize +5<CR>', opts)
map('n', '<S-j>', ':resize -5<CR>', opts)
map('n', '<S-l>', ':vertical resize +5<CR>', opts)
map('n', '<S-h>', ':vertical resize -5<CR>', opts)
-- To map <Esc> to exit terminal-mode
map('t', '<Esc>', '<C-\\><C-n>', opts)
-- Go to previous visited locations
map('n', '<C-t>', '<C-o>', opts)
map('n', '<A-Left>', '<C-o>', opts)
map('n', '<A-Right>', '<C-i>', opts)
-- Buffer navigation
map('n', '<C-Down>', ']c', opts)
map('n', '<C-Up>', '[c', opts)
map('n', ']t', ':tabnext<CR>', opts)
map('n', '[t', ':tabprevious<CR>', opts)
-- Faster indentation
map('n', '>', '>>', opts)
map('n', '<', '<<', opts)
-- F* mappings
map('n', '<F2>', ':cprevious<CR>', opts)
map('n', '<F3>', ':cnext<CR>', opts)
map('n', '<F10>', ':call ToggleNumber()<CR>', opts)
-- Play macros with Q
map('n', 'Q', '@a', opts)
map('v', 'Q', ':norm @a<CR>', opts)
map('n', 'qq', 'ZZ<CR>', opts)
-- Search but don't jump to the next word
map('n', '*', '*``', opts)
-- Fix for legacy vi inconsistency
map('n', 'Y', 'y$', opts)
-- Remap VIM 0 to first non-blank character
map('n', '0', '^', opts)
-- }}}
-- {{{ Scratchpad
local function scratch()
vim.bo.buftype = 'nofile'
vim.bo.bufhidden = 'hide'
vim.bo.swapfile = false
end
vim.api.nvim_create_user_command('Scratch', function() vim.cmd('enew') scratch() end, { nargs = 0 })
vim.api.nvim_create_user_command('SScratch', function() vim.cmd('split') vim.cmd('enew') scratch() end, { nargs = 0 })
vim.api.nvim_create_user_command('VScratch', function() vim.cmd('vsplit') vim.cmd('enew') scratch() end, { nargs = 0 })
-- }}}
-- {{{ Auto-root
local augroup = vim.api.nvim_create_augroup('AutoCD', {})
vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter', 'BufReadPost' }, {
desc = 'Automatically change current directory by matching root pattern',
group = augroup,
callback = function(args)
local root = GetRootDir()
if root ~= nil then
vim.api.nvim_set_current_dir(root)
end
end,
})
-- }}}
-- {{{ Editor settings
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
if vim.g.neovide then
vim.g.neovide_fullscreen = false
vim.g.neovide_cursor_animation_length = 0
end
-- Boost performance of rendering long lines
vim.opt.synmaxcol = 300
-- How many lines to scroll at a time, make scrolling appear faster
-- vim.opt.scrolljump = 5
if vim.fn.has("termguicolors") == 1 then
vim.opt.termguicolors = true
vim.env.NVIM_TUI_ENABLE_TRUE_COLOR = 1
end
vim.cmd.colorscheme('one')
vim.cmd.syntax = 'on'
vim.opt.mouse = 'a'
vim.opt.encoding = 'utf-8'
vim.scriptencoding = 'utf-8'
vim.opt.clipboard:append('unnamedplus')
vim.opt.foldmethod = "marker"
vim.opt.foldmarker = "{{{,}}}"
vim.opt.autochdir = true
-- This makes vim act like all other editors, buffers can exist in the background without being in a window.
vim.opt.hidden = true
vim.opt.undofile = true
vim.opt.undodir = vim.env.HOME .. '/vim_undo'
vim.opt.undolevels = 10000
vim.opt.undoreload = 10000
-- Set the location for swap files and backup files
vim.opt.directory = vim.env.HOME .. '/vim_undo'
vim.opt.backupdir = vim.env.HOME .. '/vim_undo'
-- Search settings
vim.opt.hlsearch = true
vim.opt.incsearch = true
-- Flashes matching brackets or parentheses
vim.opt.showmatch = true
-- Indentation settings
vim.opt.autoindent = true
vim.opt.smarttab = true
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.tabstop = 2
vim.opt.expandtab = true
-- Scroll settings
vim.opt.scrolloff = 5
-- Language menu
vim.opt.langmenu = 'none'
-- Autoindent (alternative setting)
vim.opt.ai = true
-- Command line completion settings
vim.opt.wildmenu = true
vim.opt.wildmode = 'full'
vim.opt.visualbell = true
vim.opt.history = 1000
-- Disable built-in plugins
vim.g.loaded_2html_plugin = 1
vim.g.loaded_gzip = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_zipPlugin = 1
vim.g.loaded_tutor_mode_plugin = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_vimballPlugin = 1
vim.g.loaded_matchit = 1
-- Show the current line
vim.opt.cul = true
-- Show the filename in the bottom of the window
vim.opt.modeline = true
vim.opt.laststatus = 2
-- Allow backspacing over everything in insert-mode
vim.opt.backspace = { 'indent', 'eol', 'start' }
vim.opt.shortmess = 'aoOTt'
-- If we have 'live substitution', enable it
if vim.fn.exists('&inccommand') == 1 then
vim.opt.inccommand = 'nosplit'
end
vim.opt.title = true
-- Set error format
vim.opt.errorformat = "%f:%l:%c:%m"
-- Set dictionary
vim.opt.dictionary:append(vim.env.HOME .. '\\words.txt')
-- C indentation settings
vim.opt.cino = vim.opt.cino + '(0'
--}}}
-- {{{ Autocmds
-- Set nowrap for quickfix file type
vim.api.nvim_create_autocmd('FileType', {pattern = 'qf', command = 'set nowrap'})
-- Set row highlight on window enter and leave
vim.api.nvim_create_augroup('BgHighlight', {clear = true })
vim.api.nvim_create_autocmd('WinEnter', {group = 'BgHighlight', command = 'set cul'})
vim.api.nvim_create_autocmd('WinLeave', {group = 'BgHighlight', command = 'set nocul'})
vim.api.nvim_create_autocmd('FileType', {pattern = 'make', command = 'setlocal noexpandtab shiftwidth=8 tabstop=8'})
local autoswap_group = vim.api.nvim_create_augroup('AutoSwap', { clear = true })
local function AS_HandleSwapfile(filename, swapname)
if vim.fn.getftime(swapname) < vim.fn.getftime(filename) then
vim.fn.delete(swapname)
vim.v.swapchoice = 'e'
end
end
vim.api.nvim_create_autocmd('SwapExists', {
group = autoswap_group,
callback = function(args)
AS_HandleSwapfile(vim.fn.expand('<afile>:p'), args.file)
end
})
--}}}
--{{{ Functions
function GetRootDir()
local root_patterns = {'.git', '.svn', 'util', 'plugin.xml'}
return vim.fs.root(vim.fn.expand('%:p'), root_patterns) or vim.fn.getcwd()
end
function PrepRgCommand(search_term)
local root_dir = GetRootDir()
local current_word = ''
local move_to_term = ''
if search_term == 'cword' then
current_word = vim.fn.expand('<cword>')
else
move_to_term = '<C-Left><C-Left><C-Left><C-Left><C-Right><Right>'
end
local cmd = ':Ack ' .. current_word .. ' ' .. root_dir..move_to_term
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(cmd, true, false, true), 'n', true)
end
function ToggleColorColumn()
if vim.wo.colorcolumn ~= '' then
vim.wo.colorcolumn = ''
else
vim.wo.colorcolumn = '100'
end
end
function ToggleNumber()
if vim.wo.relativenumber then
vim.wo.relativenumber = false
vim.wo.number = true
else
vim.wo.relativenumber = true
end
end
function DeleteInactiveBufs()
local current_buffer = vim.api.nvim_get_current_buf()
local buffers = vim.api.nvim_list_bufs()
for _, buf in ipairs(buffers) do
if vim.api.nvim_buf_is_loaded(buf) and buf ~= current_buffer then
vim.api.nvim_command('bdelete ' .. buf)
end
end
end
function ToggleVerbose()
if vim.o.verbose == 0 then