nvim配置文件

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
-- nvim 主题
vim.cmd.colorscheme("torte")

--[[
-- 安装lazy.nvim
--]]
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)

--[[
-- 基础配置
--]]
vim.opt.compatible = false -- 不使用vi兼容

vim.syntax = true -- 启用语法高亮

vim.o.number = true -- 显示行号
vim.o.relativenumber = true -- 显示相对行号
vim.o.cursorline = true -- 高亮显示当前行
vim.opt.signcolumn = 'yes' -- 始终显示标记列
vim.o.title = true -- 终端标题显示当前文件
vim.opt.scrolloff = 3 -- 光标上下保留3行缓冲

vim.o.ignorecase = true -- 搜索时忽略大小写
vim.o.smartcase = true -- 如果包含大小写则开启精确匹配
vim.o.hlsearch = true -- 高亮所有搜索结果
vim.o.incsearch = true -- 边输入边高亮匹配

vim.o.expandtab = true -- 将Tab转换为空格
vim.opt.tabstop = 4 -- Tab显示为4个空格宽度
vim.opt.shiftwidth = 4 -- 自动缩进使用4
vim.opt.softtabstop = 4 -- 在编辑时Tab键当作4个空格
vim.o.autoindent = true -- 自动缩进
vim.o.smartindent = true -- 智能缩进

vim.opt.backspace = {'indent', 'eol', 'start'} -- 允许退格键删除:缩进、换行
vim.o.wildmenu = true -- 命令模式补全时显示菜单
vim.opt.wildmode = 'longest:full,full' -- 补全模式:最长匹配,然后列表
vim.opt.updatetime = 300 -- 减少更新延迟
vim.opt.mouse = 'a' -- 启用鼠标支持

vim.opt.encoding = 'utf-8' -- 内部使用UIF-8编码
vim.opt.fileencodings = 'utf-8,gbk' -- 尝试解码的文件编码列表
vim.opt.clipboard = 'unnamedplus' -- 启用系统剪贴板支持

vim.opt.laststatus = 2 -- 始终显示状态栏
vim.opt.statusline =
[[%f %m%=[%{&fileencoding?&fileencoding:&encoding}] [%Y] %l:%c %p%%]]



--[[
-- 插件管理
--]]

-- 增强语法高亮:Markdown、Makefile、LaTeX
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = {
-- 只安装这几种语言的解析器
ensure_installed = {
"markdown", -- Markdown 基础语法
"markdown_inline",-- Markdown 内联元素(如粗体、代码)更精细的高亮
"make", -- Makefile
"latex", -- LaTeX / BibTeX
},
highlight = {
enable = true, -- 启用 Tree-sitter 高亮
additional_vim_regex_highlighting = false, -- 关闭 Vim 正则高亮避免冲突
},
},
config = function(_, opts)
-- 标准 setup 调用
require("nvim-treesitter.configs").setup(opts)
end,
},
})