-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
521 lines (463 loc) · 13.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
-- sudo dnf install nodejs yarnpkg cmake gcc g++ golang python3 python3=pip python3-neovim
-- 加载LazyNVim
local lazynvim_path = vim.fn.stdpath("data") .. "/plugin/lazy.nvim"
if not vim.loop.fs_stat(lazynvim_path) then
vim.fn.system({
"git",
"clone",
"--branch=stable",
"https://github.com/folke/lazy.nvim.git",
lazynvim_path,
})
end
vim.opt.rtp:prepend(lazynvim_path)
-- 加载插件
require("lazy").setup({
-- OneDark主题
"joshdick/onedark.vim",
-- 状态栏
"vim-airline/vim-airline",
-- Git 集成
"tpope/vim-fugitive",
-- 编辑历史
"mbbill/undotree",
-- Tag列表
"preservim/tagbar",
-- 符号闭合
"jiangmiao/auto-pairs",
-- 快速修改符号
"tpope/vim-surround",
-- 启动终端
"akinsho/toggleterm.nvim",
-- 直接开启终端并运行
"kassio/neoterm",
-- 窗口切换
"t9md/vim-choosewin",
-- 自动换行
"reedes/vim-pencil",
-- 剪贴板管理 TODO
"tversteeg/registers.nvim",
-- 自动缩进 TODO
"godlygeek/tabular",
-- 字符查找强化
"rhysd/clever-f.vim",
"easymotion/vim-easymotion",
-- 快速注释 TODO
"preservim/nerdcommenter",
-- 快捷键提示
"folke/which-key.nvim",
-- UI库
"MunifTanjim/nui.nvim",
-- 通知
"rcarriga/nvim-notify",
"folke/noice.nvim",
-- 文字对象强化
"echasnovski/mini.ai",
-- 文字范围
"echasnovski/mini.indentscope",
-- Fcitx模式自动切换
"alohaia/fcitx.nvim",
-- 专注模式
"junegunn/goyo.vim",
-- 代码观感强化
{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
-- 图标
"nvim-tree/nvim-web-devicons",
-- 文件树
"nvim-tree/nvim-tree.lua",
"nvim-tree/nvim-web-devicons",
-- 切换预设值 TODO
"andrewradev/switch.vim",
-- LSP 支持
"neovim/nvim-lspconfig",
-- LSP安装器
{ "williamboman/mason.nvim", build = ":MasonUpdate" },
"williamboman/mason-lspconfig.nvim",
"jose-elias-alvarez/null-ls.nvim",
-- 基于LSP的代码段
"L3MON4D3/LuaSnip",
"onsails/lspkind-nvim",
-- 预制的代码段
"rafamadriz/friendly-snippets",
-- 基于LSP的代码检查 TODO
"dense-analysis/ale",
-- 基于LSP的inlay hint
"lvimuser/lsp-inlayhints.nvim",
-- LSP观感强化
"nvimdev/lspsaga.nvim",
-- 代码补全支持
"hrsh7th/nvim-cmp",
-- 通过 Buffer 进行补全
"hrsh7th/cmp-buffer",
-- 通过路径进行补全
"hrsh7th/cmp-path",
-- 使用补全快速计算
"hrsh7th/cmp-calc",
-- 快速输入 Emoji
"hrsh7th/cmp-emoji",
-- 有词典的时候补全英文单词
"octaltree/cmp-look",
-- 基于LSP的补全
"hrsh7th/cmp-nvim-lsp",
-- 基于LSP的代码段补全
"saadparwaiz1/cmp_luasnip",
-- 基于GitHub Copilot的代码段补全
"zbirenbaum/copilot.lua",
"zbirenbaum/copilot-cmp",
-- 文档与Debug
"folke/neodev.nvim",
"mfussenegger/nvim-dap",
"rcarriga/nvim-dap-ui",
-- 搜索
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
-- 调试器整合
"nvim-telescope/telescope-vimspector.nvim",
-- 标题快速搜索
"crispgm/telescope-heading.nvim",
-- 文件浏览与搜索
"nvim-telescope/telescope-file-browser.nvim",
-- 环境变量搜索
"LinArcX/telescope-env.nvim",
-- FZF集成
{ "nvim-telescope/telescope-fzf-native.nvim", build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build" },
-- 代码调试 TODO
"puremourning/vimspector",
-- CMake命令
"ilyachur/cmake4vim",
-- Conda命令
"cjrh/vim-conda",
-- VirtualEnv命令
"jmcantrell/vim-virtualenv",
-- GLSL代码高亮
"tikhomirov/vim-glsl",
-- HLSL代码高亮
"beyondmarc/hlsl.vim",
-- Tex语言支持 TODO
"lervag/vimtex",
-- C++支持强化
"octol/vim-cpp-enhanced-highlight",
-- Markdown支持 TODO
"plasticboy/vim-markdown",
-- Markdown预览
{ "iamcco/markdown-preview.nvim", build = "cd app && yarn install" },
-- 无浏览器的Markdown预览
"ellisonleao/glow.nvim",
-- Rust支持
"rust-lang/rust.vim",
-- Golang支持
{ "fatih/vim-go", build = ":GoUpdateBinaries" },
-- OrgMode支持
"nvim-orgmode/orgmode",
-- Git支持
"kdheepak/lazygit.nvim",
-- 幻灯片支持
"Chaitanyabsprip/present.nvim",
})
-- 加载主题
vim.opt.termguicolors = true
vim.cmd.colorscheme("onedark")
-- 设置字体
vim.opt.guifont = "FiraCode Nerd Font Mono"
-- NeoVim个性化设置
-- 高亮
vim.cmd([[
syntax enable
filetype plugin indent on
]])
-- 行号
vim.wo.number = true
vim.wo.relativenumber = true
-- <leader>超时
vim.o.timeout = true
vim.o.timeoutlen = 300
-- 开启鼠标支持
vim.cmd("set mouse=a")
-- 设置Tab转4个空格
vim.cmd([[
set tabstop=4
set shiftwidth=4
set expandtab
]])
-- 加载状态栏
vim.g["airline#extensions#tabline#enabled"] = true
-- 初始化剪贴板管理工具
require("registers").setup({})
-- 初始化终端工具
require("toggleterm").setup({})
-- 初始化快捷键提示
require("which-key").setup({})
-- 初始化通知
require("noice").setup({})
-- 初始化文字对象强化
require("mini.ai").setup({})
-- 初始化文字范围
require("mini.indentscope").setup({})
-- 初始化文件树
vim.g["loaded_netrw"] = 1
vim.g["loaded_netrwPlugin"] = 1
require("nvim-tree").setup({})
-- 初始化OrgMode
require("orgmode").setup({})
-- 初始化无浏览器Markdown预览
require("glow").setup({})
-- 初始化幻灯片支持
require('present').setup({})
-- 初始化Telescope
require("telescope").setup({})
require("telescope").load_extension("vimspector")
require("telescope").load_extension("heading")
require("telescope").load_extension("file_browser")
require("telescope").load_extension("env")
require("telescope").load_extension("fzf")
-- 设置C++高亮强化
vim.g["cpp_class_scope_highlight"] = true
vim.g["cpp_member_variable_highlight"] = true
vim.g["cpp_class_decl_highlight"] = true
vim.g["cpp_posix_standard"] = true
vim.g["cpp_experimental_template_highlight"] = true
vim.g["cpp_concepts_highlight"] = true
-- 初始化LSP支持
require("mason").setup({})
require("mason-lspconfig").setup({
ensure_installed = {
"clangd", -- C++
"cmake", -- CMake
"rust_analyzer", -- Rust
"lua_ls", -- Lua
"bashls", -- Bash
"powershell_es", -- PowerShell
"tsserver", -- TypeScript
"yamlls", -- YAML
"dockerls", -- Docker
-- "nil_ls", -- Nix
"sqlls", -- SQL
"texlab", --LaTeX
"jedi_language_server", -- Python
"golangci_lint_ls", -- Go
"grammarly", -- English Spell Checker
"remark_ls", -- Markdown
}
})
local lspconfig = require("lspconfig")
-- lua_ls在nodev处初始化
-- clangd
lspconfig.clangd.setup( {
cmd = {
"clangd",
"--all-scopes-completion",
"--completion-style=detailed",
"--header-insertion=never",
},
})
-- bashls
lspconfig.bashls.setup({})
-- grammarly
lspconfig.grammarly.setup({})
-- remark_ls
lspconfig.remark_ls.setup({})
-- cmake
lspconfig.cmake.setup({})
-- rust_analyzer
lspconfig.rust_analyzer.setup({})
-- powershell_es
lspconfig.powershell_es.setup({})
-- tsserver
lspconfig.tsserver.setup({})
-- yamlls
lspconfig.yamlls.setup({})
-- dockerls
lspconfig.dockerls.setup({})
-- sqlls
lspconfig.sqlls.setup({})
-- texlab
lspconfig.texlab.setup({})
-- jedi_language_server
lspconfig.jedi_language_server.setup({})
-- golangci_lint_ls
lspconfig.golangci_lint_ls.setup({})
-- 初始化inlay hint
require("lsp-inlayhints").setup({})
vim.api.nvim_create_augroup("LspAttach_inlayhints", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = "LspAttach_inlayhints",
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
require("lsp-inlayhints").on_attach(client, bufnr)
end,
})
-- 初始化Copilot
require("copilot").setup({})
require("copilot_cmp").setup({})
-- 初始化代码补全
local has_words_before = function()
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 cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
-- 代码段
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
-- 补全来源
sources = {
{ name = "copilot" },
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "orgmode" },
{ name = "buffer" },
{ name = "calc" },
{ name = "path" },
{ name = "look", keyword_length=2, option={convert_case=true, loud=true}},
{ name = "emoji" },
},
-- 补全样式
formatting = {
format = require("lspkind").cmp_format {
mode = "symbol_text",
preset = "default",
-- 来源显示
menu = {
buffer = "[buf]",
nvim_lsp = "[lsp]",
luasnip = "[snip]",
calc = "[calc]",
path = "[path]",
look = "[look]",
emoji = "[emo]"
},
},
},
-- 键位映射
mapping = cmp.mapping.preset.insert ({
-- Wiki:Super-Tab Config
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
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()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-Up>"] = cmp.mapping(cmp.mapping.scroll_docs(-4)),
["<C-Down>"] = cmp.mapping(cmp.mapping.scroll_docs(4)),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
experimental = {
-- 新版菜单
native_menu = false,
-- 虚影文字
ghost_text = true,
},
})
-- "/"的补全,用于单词搜索
cmp.setup.cmdline("/", {
sources = {
{ name = "buffer" },
},
})
-- ":"的补全,用于NVIM内置命令
cmp.setup.cmdline(":", {
sources = {
{ name = "path" }
},
})
-- 初始化lspsaga
require('lspsaga').setup({})
-- 初始化nodev
require("neodev").setup({})
lspconfig.lua_ls.setup({
settings = {
Lua = {
completion = {
callSnippet = "Replace"
}
}
}
})
-- 键位绑定,<leader>默认是"\"
-- 独立工具
require("which-key").register({
s = {
name = "独立命令",
-- h=history
h = { vim.cmd.UndotreeToggle, "编辑历史" },
-- t=tag
t = { vim.cmd.TagbarToggle, "Tag列表"},
-- x = exec
x = { vim.cmd.ToggleTerm, "终端" },
-- v = vsplit
v = { vim.cmd.vsplit, "竖向分屏" },
-- c = split
c = { vim.cmd.split, "横向分屏" },
-- ge=goyo enable
ge = { vim.cmd["Goyo"], "开启专注模式" },
-- gd=goyo disable
gd = { vim.cmd["Goyo!"], "关闭专注模式" },
-- b = browser
b = { vim.cmd.NvimTreeToggle, "文件树" },
},
}, { prefix = "<leader>" })
-- choosewin
vim.keymap.set("n", "-", "<Plug>(choosewin)")
-- 窗口切换,Alt+方向键
vim.keymap.set("n", "<A-Up>", function() vim.cmd.wincmd("k") end)
vim.keymap.set("n", "<A-Down>", function() vim.cmd.wincmd("j") end)
vim.keymap.set("n", "<A-Left>", function() vim.cmd.wincmd("h") end)
vim.keymap.set("n", "<A-Right>", function() vim.cmd.wincmd("l") end)
-- Telescope
require("which-key").register({
f = {
name = "Telescope",
-- ff=find files
f = { function() vim.cmd.Telescope("find_files") end, "find_files" },
-- fb=find file_browser
b = { function() vim.cmd.Telescope("file_browser") end, "file_browser" },
-- fc=find current
c = { function() vim.cmd.Telescope("buffers") end, "buffers" },
-- fe=find env
e = { function() vim.cmd.Telescope("env") end, "env" },
-- ft=find title
t = { function() vim.cmd.Telescope("heading") end, "heading" },
-- fh=find command_history
h = { function() vim.cmd.Telescope("command_history") end, "command_history" },
-- fg = find live_grep
g = { function() vim.cmd.Telescope("live_grep") end, "live_grep" },
},
}, { prefix = "<leader>" })
-- 自定义命令
-- 编辑CMakeLists.txt
vim.api.nvim_create_user_command("CMakeCreate", "new CMakeLists.txt", { nargs = 0 })
-- 编辑compile_flags.txt
vim.api.nvim_create_user_command("ClangCompileFlagCreate", "new compile_flags.txt", { nargs = 0 })
-- 导出CMake编译命令
vim.api.nvim_create_user_command("CMakeExport", ":T cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 <args>", { nargs = "*" })
-- 清空剪贴板
vim.api.nvim_create_user_command("WipeReg", "for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor", { nargs = 0 })
-- 自动命令,与格式绑定
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
pattern = { "*.vs", "*.fs" },
command = "set ft=glsl"
})
-- 自启动
vim.cmd("NvimTreeOpen")