-
Notifications
You must be signed in to change notification settings - Fork 1
/
windows-init.lua
717 lines (671 loc) · 19.4 KB
/
windows-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
-- Install ripgrep, clang, fzf, git before proceed.
-- Helpers function
function getOS()
-- ask LuaJIT first
if jit then
return jit.os
end
-- Unix, Linux variants
local fh,err = assert(io.popen("uname -o 2>/dev/null","r"))
if fh then
osname = fh:read()
end
return osname or "Windows"
end
function map(mode, lhs, rhs, opts)
local options = {
noremap = true
}
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
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 feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local shell = "bash"
if getOS() == "Windows" then
shell = "pwsh.exe"
end
-- Options Configuration
vim.opt.syntax = "enable"
vim.opt.signcolumn = "yes"
vim.opt.showmode = true
vim.opt.wrap = false
vim.opt.smartcase = true
vim.opt.ttyfast = true
vim.opt.laststatus = 2
vim.opt.autoindent = true
vim.opt.shiftwidth = 2
vim.opt.smartindent = true
vim.opt.smarttab = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.background = "dark"
vim.opt.expandtab = true
vim.opt.list = false
vim.opt.mouse = "a"
vim.opt.undolevels = 1000
vim.opt.backspace = {"indent", "eol", "start"}
vim.o.fillchars = "vert: ,eob:│"
vim.opt.colorcolumn = "101"
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
vim.g.vscode_italic_comment = 1
vim.g.nvim_tree_respect_buf_cwd = 1
vim.opt.showtabline = 2
-- Required to use nvim-tree
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
-- Skip backwards compatibility routines and speed up loading.
vim.g.skip_ts_context_commentstring_module = true
vim.cmd [[
set foldlevelstart=99
]]
-- Initialize lazy package manager
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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Load dependencies
require("lazy").setup({
-- User Interface
-- VSCode Theme
"Mofiqul/vscode.nvim",
-- Recenter the command center, this will help by a LOT on ultrawide screen.
{
"folke/noice.nvim",
event = "VeryLazy",
opts = {
-- add any options here
},
dependencies = {
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
"MunifTanjim/nui.nvim",
-- OPTIONAL:
-- `nvim-notify` is only needed, if you want to use the notification view.
-- If not available, we use `mini` as the fallback
-- "rcarriga/nvim-notify",
}
},
-- Lualine is required since the new UI will disable the UI for VIM mode.
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }
},
-- Show code alignment like in modern IDE.
{ "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} },
'RRethy/vim-illuminate',
{
'nvim-tree/nvim-tree.lua',
dependencies = {
'nvim-tree/nvim-web-devicons',
},
},
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "VeryLazy",
config = function()
require("nvim-surround").setup({
-- Configuration here, or leave empty to use defaults
})
end
},
{
"nvim-treesitter/nvim-treesitter",
dependencies = {"JoosepAlviste/nvim-ts-context-commentstring"},
run = function()
require("nvim-treesitter.install").update({
with_sync = true
})
end
},
-- LSP
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
"mfussenegger/nvim-lint",
"mhartington/formatter.nvim",
-- Debugger
"mfussenegger/nvim-dap",
"rcarriga/nvim-dap-ui",
-- Autocomplete
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
-- Auto close tag and pair
"windwp/nvim-ts-autotag",
{
"windwp/nvim-autopairs",
config = function()
require("nvim-autopairs").setup {}
end
},
{
"numToStr/Comment.nvim",
config = function()
require("Comment").setup({
pre_hook = require("ts_context_commentstring.integrations.comment_nvim").create_pre_hook()
})
end
},
-- Debugger
-- Fuzzy Search and Grep.
{
"ibhagwan/fzf-lua",
-- optional for icon support
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require('fzf-lua').setup({
files = { cmd = 'rg --files' }
})
end
},
-- Debugging and Terminal.
{'akinsho/toggleterm.nvim', version = "*", config = true},
})
---------------------------
-- CUSTOM VANILLA BINDING
---------------------------
map("n", "tp", ":noh<CR>", {
silent = true
})
map("n", "<leader>tn", ":tabnew<CR>", {
silent = true
})
-- Syntax Highlighting
require("nvim-tree").setup({
sort_by = "case_sensitive",
update_focused_file = {
enable = true,
update_cwd = true
},
renderer = {
-- group_empty = true
indent_markers = {
enable = true,
icons = {
corner = "└ ",
edge = "│ ",
none = " "
}
}
},
filters = {
dotfiles = true
}
})
map("n", "th", ":NvimTreeToggle <CR>", {
silent = true
})
map("n", "tf", ":NvimTreeFindFile <CR>", {
silent = true
})
---------------------------
-- UI THEME
---------------------------
local c = require('vscode.colors').get_colors()
require('vscode').setup({
-- Alternatively set style in setup
-- style = 'light'
-- Enable transparent background
transparent = true,
-- Enable italic comment
italic_comments = true,
-- Disable nvim-tree background color
disable_nvimtree_bg = true,
-- Override colors (see ./lua/vscode/colors.lua)
color_overrides = {
-- vscLineNumber = '#FFFFFF',
},
-- Override highlight groups (see ./lua/vscode/theme.lua)
group_overrides = {
-- this supports the same val table as vim.api.nvim_set_hl
-- use colors from this colorscheme by requiring vscode.colors!
Cursor = { fg=c.vscDarkBlue, bg=c.vscLightGreen, bold=true },
VertSplit = {fg=c.vscFront, bg=c.vscTabOutside},
StatusLineNC = {fg=c.vscFront, bg=c.vscTabOutside}
}
})
require("vscode").load()
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'vscode',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
'NvimTree'
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
require("noice").setup({
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
})
-- require('notify').setup ({
-- background_colour = "#000000"
-- })
require"nvim-treesitter.configs".setup {
ensure_installed = {"go", "rust"},
auto_install = true,
-- context_commentstring = {
-- enable = true
-- },
highlight = {
enable = true
},
autotag = {
enable = true
},
indent = {
enable = true
}
}
-- Illuminate tag highlight.
require("illuminate").configure({
-- providers: provider used to get references in the buffer, ordered by priority
providers = {"lsp", "treesitter", "regex"},
-- delay: delay in milliseconds
delay = 100,
-- filetype_overrides: filetype specific overrides.
-- The keys are strings to represent the filetype while the values are tables that
-- supports the same keys passed to .configure except for filetypes_denylist and filetypes_allowlist
filetype_overrides = {},
-- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist
filetypes_denylist = {"dirvish", "fugitive", "NvimTree", "packer"},
-- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist
filetypes_allowlist = {},
-- modes_denylist: modes to not illuminate, this overrides modes_allowlist
-- See `:help mode()` for possible values
modes_denylist = {},
-- modes_allowlist: modes to illuminate, this is overriden by modes_denylist
-- See `:help mode()` for possible values
modes_allowlist = {},
-- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist
-- Only applies to the 'regex' provider
-- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
providers_regex_syntax_denylist = {},
-- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist
-- Only applies to the 'regex' provider
-- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
providers_regex_syntax_allowlist = {},
-- under_cursor: whether or not to illuminate under the cursor
under_cursor = true,
-- large_file_cutoff: number of lines at which to use large_file_config
-- The `under_cursor` option is disabled when this cutoff is hit
large_file_cutoff = nil,
-- large_file_config: config to use for large files (based on large_file_cutoff).
-- Supports the same keys passed to .configure
-- If nil, vim-illuminate will be disabled for large files.
large_file_overrides = nil,
-- min_count_to_highlight: minimum number of matches required to perform highlighting
min_count_to_highlight = 1
})
-- Showing IDE like blank line.
local highlight = {
-- "CursorColumn",
"Whitespace",
}
require("ibl").setup {
indent = { highlight = highlight },
scope = {
enabled = true,
show_start = true,
show_end = true,
injected_languages = false,
highlight = { "Function", "Label" },
priority = 500,
}
}
-- Fuzzy Search and Grep Search
vim.keymap.set("n", "<c-P>", "<cmd>lua require('fzf-lua').files()<CR>", { silent = true })
vim.keymap.set("n", "<C-g>", "<cmd>lua require('fzf-lua').live_grep()<CR>", {
noremap = true,
silent = true
})
vim.keymap.set("n", "<leader>tt", "<cmd>lua require('fzf-lua').loclist()<CR>", {
noremap = true,
silent = true
})
vim.keymap.set("n", "<C-a>", "<cmd>lua require('fzf-lua').buffers()<CR>", {
noremap = true,
silent = true
})
-- Terminal
require"toggleterm".setup {
size = 20,
open_mapping = [[<c-\>]],
shell = shell,
shade_terminals = true,
direction = "float"
}
-- Mason LSP, Debugger and Linter Package manager
require("mason").setup()
require("mason-lspconfig").setup()
-- Autocomplete: cmp
local cmp = require "cmp"
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered()
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({
select = true
}), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, {"i", "s"})
}),
sources = cmp.config.sources({{
name = "nvim_lsp"
}, {
name = "vsnip"
} -- For vsnip users.
}, {{
name = "buffer"
}})
})
-- Set configuration for specific filetype.
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({{
name = "cmp_git"
} -- You can specify the `cmp_git` source if you were installed it.
}, {{
name = "buffer"
}})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({"/", "?"}, {
mapping = cmp.mapping.preset.cmdline(),
sources = {{
name = "buffer"
}}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({{
name = "path"
}}, {{
name = "cmdline"
}})
})
---------------------------
-- LANGUAGE CONFIGURATION
---------------------------
local lspconfig = require("lspconfig")
local util = require("lspconfig/util")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- JavaScript TypeScript LSP
lspconfig.tsserver.setup {
capabilities = capabilities
}
-- Golang LSP
lspconfig.gopls.setup {
capabilities = capabilities,
cmd = {"gopls", "serve"},
filetypes = {"go", "gomod"},
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
analyses = {
unusedparams = true
},
staticcheck = true
}
}
}
-- Python LSP
lspconfig.pyright.setup {
capabilities = capabilities
}
-- CPP LSP
lspconfig.clangd.setup {
capabilities = capabilities
}
-- Rust LSP
lspconfig.rust_analyzer.setup {
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
diagnostics = {
enable = false
}
}
}
}
-- Auto pairs and autocomplete integration.
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
-- Native LSP Mapping
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = {
buffer = ev.buf
}
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format {
async = true
}
end, opts)
end
})
-- Format on save
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
vim.lsp.buf.format {
async = false
}
vim.lsp.buf.code_action({
context = {
only = {"source.organizeImports"}
},
apply = true
})
end
})
vim.api.nvim_create_autocmd("BufEnter", {
callback = function()
if vim.opt.foldmethod:get() == "expr" then
vim.schedule(function()
vim.opt.foldmethod = "expr"
end)
end
end,
})
-- Debuggers Configuration.
vim.keymap.set("n", "<leader>b", function()
require("dap").toggle_breakpoint()
end)
vim.keymap.set("n", "F5", function()
require("dap").continue()
end)
-- Debugger Setup using DAP
local dap = require("dap")
dap.adapters.lldb = {
type = "executable",
command = "/usr/bin/lldb-vscode-14", -- Change this if the version of lldb is different.
name = "lldb"
}
-- CPP Debugger
dap.configurations.cpp = {
name = "Launch",
type = "lldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}"
}
-- C Debugger
dap.configurations.c = dap.configurations.cpp
-- Rust Debugger
dap.configurations.rust = {
name = "Launch",
type = "lldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
initCommands = function()
-- Find out where to look for the pretty printer Python module
local rustc_sysroot = vim.fn.trim(vim.fn.system("rustc --print sysroot"))
local script_import = "command script import \"" .. rustc_sysroot .. "/lib/rustlib/etc/lldb_lookup.py\""
local commands_file = rustc_sysroot .. "/lib/rustlib/etc/lldb_commands"
local commands = {}
local file = io.open(commands_file, "r")
if file then
for line in file:lines() do
table.insert(commands, line)
end
file:close()
end
table.insert(commands, 1, script_import)
return commands
end
}
-- Golang Debugger
dap.adapters.delve = {
type = "server",
port = "${port}",
executable = {
command = "dlv",
args = {"dap", "-l", "127.0.0.1:${port}"}
}
}
dap.configurations.go = {{
type = "delve",
name = "Debug",
request = "launch",
program = "${file}"
}, {
type = "delve",
name = "Debug test", -- configuration for debugging test files
request = "launch",
mode = "test",
program = "${file}"
}, -- works with go.mod packages and sub packages
{
type = "delve",
name = "Debug test (go.mod)",
request = "launch",
mode = "test",
program = "./${relativeFileDirname}"
}}