diff --git a/.gitignore b/.gitignore index e033bc6..47f5852 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ lazy-lock.json +nvim.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee9f5ff --- /dev/null +++ b/README.md @@ -0,0 +1,172 @@ +# Neovim 配置 + +基于 Neovim 0.12+,lazy.nvim 管理插件,支持原生和 VSCode Neovim 双模式。 + +## 目录结构 + +``` +init.lua # 入口:安装 lazy.nvim → keymaps → 分支判断 +lua/ + G.lua # 全局工具单例(vim API 别名 + 映射/命令/自动命令封装) + keymap.lua # 基础快捷键 + options.lua # vim.opt 基础设置 + vsc.lua # VSCode Neovim 模式下的精简启动(仅编辑插件) + plugs.lua # 插件聚合器(10 个模块) + plugs/ + nvim-lspconfig.lua # LSP 核心:7 个 server 注册 + LSP 快捷键 + mason.lua # LSP server 自动安装(Mason) + nvim-cmp.lua # 补全引擎(nvim-cmp + vsnip + lspkind + 命令行补全) + treesitter.lua # 语法高亮 + 自动安装 parser + symbols-outline.lua # 代码大纲侧边栏 + winbar.lua # 顶部文件路径 + 函数标签 + nvimtree.lua # 文件树 + theme.lua # 主题(tokyonight)+ 状态栏(lualine)+ 标签栏(tabline) + edit-plugs.lua # 编辑增强(fzf/surround/wildfire/多光标/对齐/Copilot/折叠/hop) + dev.lua # 开发工具(colorizer/go.nvim/conda/toggleterm) + lsp/ + lua.lua # Lua LSP(LuaJIT + 全局变量声明) + c.lua # C/C++ LSP(clangd)+ :R 编译运行 + bash.lua # Bash LSP + :R 运行 + go.lua # Go LSP(gopls)+ :R / :Rgin 运行 + basedpyright.lua # Python LSP(basedpyright)+ :R 运行 + yaml.lua # YAML LSP + GitHub Workflow schema + json.lua # JSON LSP +snippets/ # 代码片段(C/Go/JSON/Lua) +``` + +## 启动流程 + +``` +G.lua → 克隆/定位 lazy.nvim → keymap.lua → + 若 VSCode 环境 → vsc.lua(仅编辑插件) + 若原生 Neovim → options.lua → lazy.setup(plugs.lua) +``` + +## 插件总表(~28 个) + +| 分类 | 插件 | 用途 | +|------|------|------| +| LSP | nvim-lspconfig | LSP 客户端配置 | +| LSP | Mason + mason-lspconfig | LSP server 自动下载 | +| LSP | lua_ls, clangd, bashls, gopls, basedpyright, yamlls, jsonls | 7 种语言 LSP | +| 补全 | nvim-cmp + cmp-nvim-lsp + cmp-buffer + cmp-path + cmp-cmdline | 补全引擎 | +| 补全 | vim-vsnip + cmp-vsnip | 代码片段引擎 | +| 补全 | lspkind-nvim | 补全图标 | +| 语法 | nvim-treesitter | 语法高亮 + 缩进检测 | +| 语法 | nvim-autopairs | 自动括号配对 | +| 语法 | nvim-hlchunk | 括号层级和缩进色块 | +| 主题 | tokyonight.nvim | 配色方案 | +| UI | lualine.nvim | 状态栏 | +| UI | tabline.nvim | 顶部标签栏 | +| UI | winbar.nvim | 顶部文件名 + 函数路径 | +| UI | nvim-tree.lua | 侧边文件树 | +| UI | symbols-outline.nvim | 代码大纲 | +| UI | colorizer | 颜色值可视化 | +| 编辑 | nvim-fzf | 模糊搜索 | +| 编辑 | vim-surround | 环绕字符操作(cs/ds/ys) | +| 编辑 | wildfire.vim | 选区自动扩大/缩小 | +| 编辑 | vim-multiple-cursors | 多光标编辑 | +| 编辑 | vim-easy-align | 对齐排版 | +| 编辑 | hop.nvim | 快速跳转(替代 f/F/t/T) | +| 编辑 | nvim-ufo | 现代折叠(treesitter 驱动) | +| AI | copilot.vim | GitHub Copilot 行内补全 | +| 语言 | go.nvim | Go 开发增强(test/coverage 等) | +| 语言 | nvim-conda | Conda 环境切换 | +| 终端 | toggleterm.nvim | 浮层终端 | + +## 快捷键速查 + +### 基础操作 + +| 键 | 模式 | 功能 | +|----|------|------| +| `nh` | n | 清除搜索高亮 | +| `rp` | n | 全局替换 `:%s/` | +| `y` / `p` / `v` | n | 全文件复制/粘贴/全选 | +| `` / `` | n | 切换左右标签页 | +| `` | n | 窗口间跳转 | +| `` / `` | n | 关闭窗口 / 强制关闭 | +| `` | n | sudo 强制保存 | +| `` | v | 复制到系统剪切板 | +| `` | n | 文件树开关 | +| `` | n | 代码大纲开关 | +| `` | n/i | 终端开关 | +| `` | n | Reasonix AI:自适应分屏(横屏→下方,竖屏→右侧) | +| `` | n | 调整窗口大小 | + +### LSP + +| 键 | 模式 | 功能 | +|----|------|------| +| `gd` | n | 跳转到定义 | +| `gh` | n | 悬浮文档 | +| `gD` | n | 跳转到声明 | +| `gi` | n | 跳转到实现 | +| `gr` | n | 查找引用 | +| `` | n | 重命名符号 | +| `` | n | 代码格式化 | + +### 语言运行 `:R` + +| 语言 | 命令 | +|------|------| +| C/C++ | 编译 → 运行 → 删二进制 | +| Bash | `sh %` | +| Go | `go run %`;`:Rgin` 运行 `main.go` | +| Python | `python3 %` | + +### 补全(插入模式) + +| 键 | 功能 | +|----|------| +| `` / `` | 选择补全项 / snippet 占位跳转 | +| ``(未选择时) | 换行 | +| ``(选择后) | 确认补全 | +| `Tab` | Copilot 接受建议 | + +### 命令栏 / 搜索栏补全 + +| 键 | 功能 | +|----|------| +| `Tab` / `S-Tab` | 选择补全项 | +| ``(未选择时) | 直接执行命令/搜索 | +| ``(选择后) | 确认补全 | + +### 编辑 + +| 键 | 模式 | 功能 | +|----|------|------| +| `f` / `F` / `t` / `T` | n | hop 行内跳转(覆盖原生) | +| `` | n | hop 双字符跳转 | +| `ga` / `=` | v | EasyAlign 对齐 | +| `gc` / `gcc` | n | 注释切换(Neovim 0.12 内置) | +| `zc` / `zo` / `za` / `zR` | n | 折叠(ufo) | + +### 文件树内 + +| 键 | 功能 | +|----|------| +| `v` | 垂直分屏打开 | +| `s` | 水平分屏打开 | + +## LSP 说明 + +- 使用 Neovim 0.11+ 新 API:`vim.lsp.config` / `vim.lsp.enable` +- `capabilities` 由 `cmp_nvim_lsp` 统一在 `nvim-lspconfig.lua` 注入,各语言文件不重复 require +- `basedpyright` 替代了 `pyright`(类型检查更强) +- Mason 自动安装:bashls、lua_ls、jsonls、yamlls(basedpyright 需手动装) +- Treesitter 关闭了 txt parser,禁用了 Go(恢复中由 go.nvim 处理) + +## 安装 + +```bash +# 克隆到 Neovim 配置目录 +git clone https://git.qyhhh.top/newbie/nvim.git ~/.config/nvim + +# 首次启动会自动安装 lazy.nvim 及全部插件 +nvim +``` + +## 许可 + +MIT diff --git a/init.lua b/init.lua index 8f3288c..3504cc5 100644 --- a/init.lua +++ b/init.lua @@ -1,47 +1,34 @@ G = require('G') - -if not G.g.vscode then - - local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" - - if not G.loop.fs_stat(lazypath) then - G.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) - - - G.fn.system({ - "git", - "config", - "--global", - "credential.helper", - "store", - }) - end - - G.opt.rtp:prepend(lazypath) - - require("keymap") - - - if G.g.vscode then - require('vscode') - else - require("options") - local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" - require("lazy").setup( - require('plugs'), { - lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", - git = { - url_format = clone_prefix, - } - } - ) - end +-- lazy.nvim 必须在 VSCode 和原生环境都可用:原生用它装插件,VSCode 的 vsc.lua 也需要 require('lazy') +local lazypath = G.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not G.loop.fs_stat(lazypath) then + G.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', + lazypath, + }) +end +G.opt.rtp:prepend(lazypath) + +-- keymap 在两个环境都加载(基础键位都不依赖插件) +require('keymap') + +if G.g.vscode then + -- VSCode Neovim 模式:只加载编辑插件,不加载 LSP/补全/主题/选项 + require('vscode') +else + require('options') + local clone_prefix = G.use_ssh and 'git@github.com:%s.git' or 'https://github.com/%s.git' + require('lazy').setup( + require('plugs'), { + lockfile = G.fn.stdpath('data') .. '/lazy/lazy-lock.json', + git = { + url_format = clone_prefix, + } + } + ) end diff --git a/lua/G.lua b/lua/G.lua index 6fe8152..70eaf76 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -13,28 +13,16 @@ G.lb = vim.lsp.buf G.dic = vim.diagnostic G.cgp = vim.nvim_create_augroup +-- 批量设置键映射,3 元素自动加 { noremap = true },4 元素用传入的 opts function G.map(maps) for _, map in pairs(maps) do - if #map == 3 then - vim.keymap.set(map[1], map[2], map[3], { noremap = true }) - elseif #map == 4 then - vim.keymap.set(map[1], map[2], map[3], map[4]) - else - print("太多变量了") - end - --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) + vim.keymap.set(map[1], map[2], map[3], map[4] or { noremap = true }) end end function G.delmap(maps) for _, map in pairs(maps) do - if #map == 2 then - vim.keymap.del(map[1], map[2], {}) - elseif #map == 3 then - vim.keymap.del(map[1], map[2], map[3]) - else - print("太多变量了") - end + vim.keymap.del(map[1], map[2], map[3] or {}) end end @@ -54,6 +42,15 @@ function G.au(even, opts) return G.api.nvim_create_autocmd(even, opts) end +-- :R 命令工厂:在下方分屏开终端运行指定命令,省去 5 个 LSP 文件的重复代码 +function G.run_cmd(cmd) + return function() + G.cmd [[set splitbelow | sp]] + G.cmd("term " .. cmd) + G.cmd [[resize 10 | startinsert]] + end +end + G.g.mapleader = ' ' return G diff --git a/lua/keymap.lua b/lua/keymap.lua index 9b04fd1..8f30f02 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -1,46 +1,40 @@ -local opt = { noremap = true } - -- base G.map({ - { 'n', 'nh', ':nohlsearch', opt }, - { 'n', 'rp', ':%s/', opt }, + { 'n', 'nh', ':nohlsearch' }, + { 'n', 'rp', ':%s/' }, - { 'v', 'L', '$', opt }, - { 'v', 'H', '^', opt }, - { 'n', 'L', '$', opt }, - { 'n', 'H', '^', opt }, - { 'v', '>', '>gv', opt }, - { 'v', '<', '', '>gv' }, + { 'v', '<', '', '>>', opt }, - { 'n', '<', '<<', opt }, - { 'n', '?', ':set hlsearch?', opt }, - { 'n', '/', ':set hlsearch/', opt }, + { 'n', '>', '>>' }, + { 'n', '<', '<<' }, + { 'n', '?', ':set hlsearch?' }, + { 'n', '/', ':set hlsearch/' }, - { 'n', '', ':tabn', opt }, - { 'n', '', ':tabp', opt }, + { 'n', '', ':tabn' }, + { 'n', '', ':tabp' }, + { 'n', '', 'j' }, + { 'n', '', 'h' }, + { 'n', '', 'k' }, + { 'n', '', 'l' }, - { 'n', '', 'j', opt }, - { 'n', '', 'h', opt }, - { 'n', '', 'k', opt }, - { 'n', '', 'l', opt }, + { 'n', '', ':q' }, + { 'n', '', ':w !sudo tee %' }, + { 'n', '', ':q!' }, + { 'v', '', '"+y' }, + { 'n', 'y', 'ggyG' }, + { 'n', 'p', 'ggpG' }, + { 'n', 'v', 'ggVG' }, - { 'n', '', ':q', opt }, - { 'n', '', ':w !sudo tee %', opt }, - { 'n', '', ':q!', opt }, - { 'v', '', '"+y', opt }, - - - - { 'n', 'y', 'ggyG', opt }, - { 'n', 'p', 'ggpG', opt }, - { 'n', 'v', 'ggVG', opt }, - - { 'n', '', ':res -5', opt }, - { 'n', '', ':res +5', opt }, - { 'n', '', ':vertical resize -5', opt }, - { 'n', '', ':vertical resize +5', opt }, - + { 'n', '', ':res -5' }, + { 'n', '', ':res +5' }, + { 'n', '', ':vertical resize -5' }, + { 'n', '', ':vertical resize +5' }, }) + diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua index 3be769f..fa32aee 100644 --- a/lua/lsp/basedpyright.lua +++ b/lua/lsp/basedpyright.lua @@ -1,5 +1,5 @@ return { - -- capabilities = require("cmp_nvim_lsp").default_capabilities(), + -- basedpyright:pyright 的增强分支,类型检查更强。capabilities 由 nvim-lspconfig.lua 统一注入 settings = { basedpyright = { analysis = { @@ -11,12 +11,6 @@ return { }, }, on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term python3 %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('python3 %'), {}) end } diff --git a/lua/lsp/bash.lua b/lua/lsp/bash.lua index 74c9c6a..978ef55 100644 --- a/lua/lsp/bash.lua +++ b/lua/lsp/bash.lua @@ -1,11 +1,5 @@ return{ on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term sh %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('sh %'), {}) end } diff --git a/lua/lsp/c.lua b/lua/lsp/c.lua index b34d457..3c006ed 100644 --- a/lua/lsp/c.lua +++ b/lua/lsp/c.lua @@ -1,11 +1,5 @@ return { on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term g++ "%" -o "%<" && ./"%<" && rm "%<"]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('g++ "%" -o "%<" && ./"%<" && rm "%<"'), {}) end } diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua index 4b7eef4..52a9b61 100644 --- a/lua/lsp/go.lua +++ b/lua/lsp/go.lua @@ -1,18 +1,7 @@ return { + -- gopls + :R(go run %)+ :Rgin(go run ./main.go,主入口专用) on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term go run %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) - G.api.nvim_create_user_command('Rgin', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term go run ./main.go]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('go run %'), {}) + G.api.nvim_create_user_command('Rgin', G.run_cmd('go run ./main.go'), {}) end } diff --git a/lua/lsp/json.lua b/lua/lsp/json.lua index a6cd7dd..a564707 100644 --- a/lua/lsp/json.lua +++ b/lua/lsp/json.lua @@ -1,4 +1 @@ -return { - on_attach = function() - end -} +return {} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua index fdd0fde..288722d 100644 --- a/lua/lsp/lua.lua +++ b/lua/lsp/lua.lua @@ -5,8 +5,6 @@ table.insert(runtime_path, "lua/?/init.lua") return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), - settings = { Lua = { diff --git a/lua/lsp/yaml.lua b/lua/lsp/yaml.lua index 7990cc8..2bd9f59 100644 --- a/lua/lsp/yaml.lua +++ b/lua/lsp/yaml.lua @@ -1,5 +1,4 @@ return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), settings = { yaml = { schemas = { diff --git a/lua/options.lua b/lua/options.lua index 1a7ef51..d6bafc5 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,4 +1,3 @@ --- G.opt.ttimeout = true G.opt.ttimeoutlen = 100 @@ -8,7 +7,6 @@ G.opt.rnu = true G.opt.scrolloff = 999 -- 自动保存 -G.opt.autowrite = true G.opt.autowriteall = true -- tab键 @@ -31,24 +29,18 @@ G.opt.ignorecase = true G.opt.incsearch = true -- 不换行 -G.opt.textwidth = 999 +G.opt.textwidth = 0 G.opt.wrap = false -- 文件判断 G.cmd("filetype plugin indent on") --- 取消换行注释 -G.au({ "BufEnter" }, { - pattern = { "*" }, - callback = function() - -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } - G.opt.formatoptions = G.opt.formatoptions - - "o" -- O and o, don't continue comments - + "r" -- But do continue when pressing enter. - end, -}) +-- 取消换行注释:o 和 O 不自动续注释;回车继续续注释(一次设定,formatoptions 不会变) +G.opt.formatoptions = G.opt.formatoptions - "o" + "r" + +-- 进入插入模式时自动关搜索高亮(个人偏好:打字时不想被高亮干扰) G.au({ "InsertEnter" }, { pattern = { "*" }, callback = function() @@ -56,6 +48,7 @@ G.au({ "InsertEnter" }, { end, }) +-- .code-snippets 文件强制识别为 JSON(方便编辑,否则无法语法高亮) G.au({ "VimEnter", "BufEnter" }, { pattern = { "*.code-snippets" }, callback = function() @@ -63,14 +56,8 @@ G.au({ "VimEnter", "BufEnter" }, { end, }) --- G.au({ --- {"CmdlineEnter"}, --- { --- if index --- } --- }) - +-- 自动检测 Conda Python 环境,优先用 conda 里的 python local function isempty(s) return s == nil or s == "" end diff --git a/lua/plugs.lua b/lua/plugs.lua index 586ff2b..8665e53 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -1,32 +1,13 @@ return { - require('plugs.nvim-lspconfig'), - require('plugs.nvimtree'), -- nvimtree - require('plugs.theme'), -- theme - require("plugs.edit-plugs"), - require("plugs.dev"), - - - -- leetcode刷题 - -- { - -- "kawre/leetcode.nvim", - -- build = ":TSUpdate html", - -- dependencies = { - -- "nvim-telescope/telescope.nvim", - -- "nvim-lua/plenary.nvim", -- telescope 所需 - -- "MunifTanjim/nui.nvim", - - -- -- 可选 - -- "nvim-treesitter/nvim-treesitter", - -- "rcarriga/nvim-notify", - -- "nvim-tree/nvim-web-devicons", - -- }, - -- opts = { - -- -- 配置放在这里 - -- cn = { - -- enabled = true, - -- }, - -- }, - -- }, - + require('plugs.mason'), + require('plugs.symbols-outline'), + require('plugs.nvim-cmp'), + require('plugs.treesitter'), + require('plugs.winbar'), + require('plugs.nvimtree'), + require('plugs.theme'), + require('plugs.edit-plugs'), + require('plugs.dev'), + require('plugs.QQdock'), } diff --git a/lua/plugs/QQdock.lua b/lua/plugs/QQdock.lua new file mode 100644 index 0000000..e750c80 --- /dev/null +++ b/lua/plugs/QQdock.lua @@ -0,0 +1,31 @@ +-- QQdock.nvim — 持久化自适应终端 +-- 远程仓库:https://git.qyhhh.top/newbie/QQdock.nvim +-- 本地临时副本:lua/QQdock/init.lua(根分区只读期间使用) +-- +-- 恢复读写后操作: +-- 1. 删掉 lua/QQdock/ +-- 2. plugs.lua 追加 require('plugs.QQdock') +-- 3. keymap.lua 不用改(require('QQdock') 自动找到 lazy 安装的版本) + +return { + { + 'newbie/QQdock.nvim', + url = 'https://git.qyhhh.top/newbie/QQdock.nvim.git', + dependencies = { 'akinsho/toggleterm.nvim' }, + config = function() + local Q = require('QQdock') + pcall(Q.setup, Q, { + size = { + horizontal = 10, + vertical = 40, + }, + }) + G.map({ + { 'n', '', Q.shell, { noremap = true } }, + { 'i', '', Q.shell, { noremap = true } }, + { 'n', '', function() Q.open('reasonix') end, { noremap = true } }, + { 'n', 'gg', function() Q.open('lazygit') end, { noremap = true } }, + }) + end, + }, +} diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index e332706..f5e3b6c 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -8,43 +8,42 @@ return { -- }) -- end -- }, - -- { - -- -- go开发 - -- "ray-x/go.nvim", - -- dependencies = { -- optional packages - -- "ray-x/guihua.lua", - -- "neovim/nvim-lspconfig", - -- "nvim-treesitter/nvim-treesitter", - -- }, - -- config = function() - -- require("go").setup() - -- end, - -- -- event = { "CmdlineEnter" }, - -- ft = { "go", 'gomod' }, - -- build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries - -- }, + { + -- go 开发:只对 go/gomod 文件加载,build 时检测是否装了 Go(无 Go 环境静默跳过) + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + ft = { "go", 'gomod' }, + build = function() + if vim.fn.executable('go') == 1 then + require("go.install").update_all_sync() + end + end, + config = function() + require("go").setup() + end, + }, { -- conda 环境 "kmontocam/nvim-conda", dependencies = { "nvim-lua/plenary.nvim" }, }, { - -- 终端 + -- toggleterm:被 addons/QQdock 使用的底层终端 'akinsho/toggleterm.nvim', version = "*", config = function() require("toggleterm").setup { - -- size can be a number or function which is passed the current terminal size = 10, - open_mapping = [[]], - hide_numbers = true, -- hide the number column in toggleterm buffers + hide_numbers = true, shade_filetypes = {}, shade_terminals = true, - shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + shading_factor = 1, start_in_insert = true, - insert_mappings = true, -- whether or not the open mapping applies in insert mode persist_size = true, - direction = 'horizontal', } end } diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua index d7fe61b..b8a3026 100644 --- a/lua/plugs/edit-plugs.lua +++ b/lua/plugs/edit-plugs.lua @@ -13,56 +13,60 @@ return { { 'terryma/vim-multiple-cursors', }, + --格式整理 { - --格式整理 - { - 'junegunn/vim-easy-align', - config = function() - G.map({ - { "v", "ga", ":EasyAlign", { noremap = true } }, - { "v", "=", ":EasyAlign", { noremap = true } }, - }) - end - }, - }, - { - -- 注释插件 - { - 'tpope/vim-commentary', - } + 'junegunn/vim-easy-align', + config = function() + G.map({ + { "v", "ga", ":EasyAlign", { noremap = true } }, + { "v", "=", ":EasyAlign", { noremap = true } }, + }) + end }, + -- 注释插件:Neovim 0.12 内置 treesitter gc/gcc 注释切换,暂注释掉此插件测试 + -- { + -- 'tpope/vim-commentary', + -- }, { + -- Copilot 懒加载:只在插入模式需要(和 nvim-cmp 共用 Tab 键,cmp 改用 C-n/C-p 避让) 'github/copilot.vim', -- github copilot + event = "InsertEnter", }, { 'windwp/nvim-autopairs', event = "InsertEnter", - opts = {}, -- this is equalent to setup({}) function config = function() require('nvim-autopairs').setup({ disable_filetype = { "vim" }, }) end }, - -- { - -- 'kevinhwang91/nvim-ufo', - -- dependencies = { - -- 'kevinhwang91/promise-async' - -- }, - -- config = function () - -- require("ufo").setup() - -- end - - -- }, { - -- hop + 'kevinhwang91/nvim-ufo', + dependencies = { + 'kevinhwang91/promise-async' + }, + config = function() + vim.opt.foldcolumn = '0' + vim.opt.foldlevel = 99 + vim.opt.foldlevelstart = 99 + vim.opt.foldenable = true + require("ufo").setup({ + provider_selector = function(bufnr, filetype, buftype) + return { 'treesitter', 'indent' } + end + }) + end + }, + { + -- hop 快速跳转:用 f/F/t/T 做行内单字符跳转, 做双字符跳转 + -- 注意:这会覆盖 Vim 原生的 f/F/t/T "phaazon/hop.nvim", branch = "v2", keys = { "f", "F", "t", "T", "" }, - lazy = true, config = function() require("hop").setup { keys = 'asdfghjkl;' } local hop = require('hop') diff --git a/lua/plugs/mason.lua b/lua/plugs/mason.lua new file mode 100644 index 0000000..831b658 --- /dev/null +++ b/lua/plugs/mason.lua @@ -0,0 +1,29 @@ +return { + { + -- lsp 下载器 + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", + }, + config = function() + require "mason".setup { + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + } + require("mason-lspconfig").setup({ + ensure_installed = { + "bashls", + -- "basedpyright", -- Python LSP 需手动装(有的机器不用 Python) + "lua_ls", + "jsonls", + "yamlls", + } + }) + end + }, +} diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua new file mode 100644 index 0000000..60bd2a4 --- /dev/null +++ b/lua/plugs/nvim-cmp.lua @@ -0,0 +1,152 @@ +return { + { + -- lsp补全 + "hrsh7th/nvim-cmp", + dependencies = { + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + { + 'hrsh7th/vim-vsnip', + config = function() + G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" + end + }, + 'hrsh7th/cmp-vsnip', + 'onsails/lspkind-nvim', + }, + config = function() + local has_words_before = function() + local cursor = G.api.nvim_win_get_cursor(0) + local line, col = cursor[1], cursor[2] + return col ~= 0 and G.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 cmp = require('cmp') + local cmp_opt = { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + -- 补全来源优先级:LSP > 片段 > buffer > 路径 + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + }, + { name = 'buffer' }, + { name = 'path' } + ), + -- 插入模式映射:C-n/C-p 选择,CR 未选时换行(避免冲突 Copilot 的 Tab) + mapping = cmp.mapping.preset.insert({ + + -- 回车:手动选择后确认,未选时 fallback 到换行 + [""] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), + c = function(fallback) + if cmp.visible() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + }), + + -- C-n:选下一个补全项 / 展开 vsnip 占位 / 手动触发补全 + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + }), + + window = { + completion = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + col_offset = -3, + side_padding = 0, + border = "rounded", + scrollbar = false, + }, + documentation = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + border = "rounded", + scrollbar = false, + }, + }, + + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + return kind + end, + }, + } + require('cmp').setup(cmp_opt) + + -- 命令栏补全:Tab 导航,回车时若有手动选择则确认,否则直接执行命令(不卡住) + require('cmp').setup.cmdline(':', { + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() -- 没选的时候 fallback = 直接执行命令 + end + end, + }), + }, + sources = { + { name = 'cmdline' }, + { name = 'path' }, + } + }) + + -- 搜索栏补全 + require('cmp').setup.cmdline('/', { + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() + end + end, + }), + }, + sources = { + { name = 'buffer' }, + } + }) + end, + }, +} diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index 9edd0b6..f19e1cb 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -4,11 +4,11 @@ return { "neovim/nvim-lspconfig", dependencies = { "folke/neodev.nvim", + "hrsh7th/cmp-nvim-lsp", }, config = function() require 'neodev'.setup {} - -- 定义需要启用的服务器列表及其对应的配置 local servers = { lua_ls = require('lsp.lua'), clangd = require('lsp.c'), @@ -19,333 +19,23 @@ return { jsonls = require('lsp.json'), } - -- 使用 Neovim 0.11+ 的新 API 进行配置和启用 + -- capabilities 在此处统一注入,各 lsp/*.lua 不单独 require cmp_nvim_lsp + -- 避免模块层面 require 带来的隐式依赖 + local capabilities = require('cmp_nvim_lsp').default_capabilities() for server, config in pairs(servers) do + config.capabilities = capabilities vim.lsp.config(server, config) vim.lsp.enable(server) end - -- require 'lspconfig'.lua_ls.setup(require('lsp.lua')) - -- require 'lspconfig'.clangd.setup(require('lsp.c')) - -- require 'lspconfig'.bashls.setup(require('lsp.bash')) - -- require 'lspconfig'.basedpyright.setup(require('lsp.basedpyright')) - -- require 'lspconfig'.yamlls.setup(require('lsp.yaml')) - -- require 'lspconfig'.gopls.setup(require('lsp.go')) - -- require 'lspconfig'.jsonls.setup(require('lsp.json')) - G.map({ - - { 'n', 'rn', 'lua vim.lsp.buf.rename()' }, - + { 'n', '', 'lua vim.lsp.buf.rename()' }, { 'n', 'gd', 'lua vim.lsp.buf.definition()' }, { 'n', 'gh', 'lua vim.lsp.buf.hover()' }, { 'n', 'gD', 'lua vim.lsp.buf.declaration()' }, { 'n', 'gi', 'lua vim.lsp.buf.implementation()' }, { 'n', 'gr', 'lua vim.lsp.buf.references()' }, { 'n', '', 'lua vim.lsp.buf.format()' }, - - }) - end - - }, - { - -- lsp - "williamboman/mason-lspconfig.nvim", - dependencies = { - "williamboman/mason.nvim", -- lsp 下载器 - }, - config = function() - require "mason".setup { - ui = { - icons = { - package_installed = "✓", - package_pending = "➜", - package_uninstalled = "✗" - } - } - } - require("mason-lspconfig").setup({ - ensure_installed = { - "bashls", - -- "basedpyright", - "lua_ls", - "jsonls", - "yamlls", - } - }) - end - }, - { -- - 'simrat39/symbols-outline.nvim', - config = function() - local opts = { - highlight_hovered_item = true, - show_guides = true, - auto_preview = false, - position = 'right', - relative_width = true, - width = 25, - auto_close = false, - show_numbers = false, - show_relative_numbers = false, - show_symbol_details = true, - preview_bg_highlight = 'Pmenu', - autofold_depth = nil, - auto_unfold_hover = true, - fold_markers = { '', '' }, - wrap = false, - keymaps = { -- These keymaps can be a string or a table for multiple keys - close = { "", "q" }, - goto_location = "", - focus_location = "h", - hover_symbol = "", - toggle_preview = "K", - rename_symbol = "r", - code_actions = "a", - fold = "o", - unfold = "l", - fold_all = "W", - unfold_all = "E", - fold_reset = "R", - }, - lsp_blacklist = {}, - symbol_blacklist = {}, - symbols = { - File = { icon = "", hl = "@text.uri" }, - Module = { icon = "", hl = "@namespace" }, - Namespace = { icon = "", hl = "@namespace" }, - Package = { icon = "", hl = "@namespace" }, - Class = { icon = "𝓒", hl = "@type" }, - Method = { icon = "ƒ", hl = "@method" }, - Property = { icon = "", hl = "@method" }, - Field = { icon = "", hl = "@field" }, - Constructor = { icon = "", hl = "@constructor" }, - Enum = { icon = "ℰ", hl = "@type" }, - Interface = { icon = "ﰮ", hl = "@type" }, - Function = { icon = "", hl = "@function" }, - Variable = { icon = "", hl = "@constant" }, - Constant = { icon = "", hl = "@constant" }, - String = { icon = "𝓐", hl = "@string" }, - Number = { icon = "#", hl = "@number" }, - Boolean = { icon = "⊨", hl = "@boolean" }, - Array = { icon = "", hl = "@constant" }, - Object = { icon = "⦿", hl = "@type" }, - Key = { icon = "🔐", hl = "@type" }, - Null = { icon = "NULL", hl = "@type" }, - EnumMember = { icon = "", hl = "@field" }, - Struct = { icon = "𝓢", hl = "@type" }, - Event = { icon = "🗲", hl = "@type" }, - Operator = { icon = "+", hl = "@operator" }, - TypeParameter = { icon = "𝙏", hl = "@parameter" }, - Component = { icon = "", hl = "@function" }, - Fragment = { icon = "", hl = "@constant" }, - }, - } - require("symbols-outline").setup(opts) - G.map({ - { "n", "", "SymbolsOutline", { noremap = true } }, - }) - end - }, - { - -- lsp补全 - { - "hrsh7th/nvim-cmp", - dependencies = { - 'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' } - 'hrsh7th/cmp-buffer', -- { name = 'buffer' }, - 'hrsh7th/cmp-path', -- { name = 'path' } - 'hrsh7th/cmp-cmdline', -- { name = 'cmdline' } - { - 'hrsh7th/vim-vsnip', - config = function() - G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" - end - }, - 'hrsh7th/cmp-vsnip', - 'onsails/lspkind-nvim', - }, - config = function() - local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(G.api.nvim_win_get_cursor(0)) - return col ~= 0 and G.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 cmp = require('cmp') - local cmp_opt = { - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - end, - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, - }, - { name = 'buffer' }, - { name = 'path' } - ), - mapping = cmp.mapping.preset.insert({ - - [""] = cmp.mapping({ - i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), - c = function(fallback) - if cmp.visible() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) - else - fallback() - end - end, - }), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - - [""] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") - end - end, { "i", "s" }), - - }), - - window = { - completion = { - winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", - col_offset = -3, - side_padding = 0, - border = "rounded", - scrollbar = false, - }, - documentation = { - winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", - border = "rounded", - scrollbar = false, - }, - }, - - formatting = { - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) - local strings = vim.split(kind.kind, "%s", { trimempty = true }) - kind.kind = " " .. (strings[1] or "") .. " " - kind.menu = " (" .. (strings[2] or "") .. ")" - return kind - end, - }, - } - require('cmp').setup(cmp_opt) - end, - }, - - { - -- 语法高亮 -- - 'nvim-treesitter/nvim-treesitter', - config = function() - local treesitter_opt = { - ensure_installed = { - -- "c", - -- "cpp", - -- "python", - -- "java", - -- "lua", - -- "bash", - -- "vimdoc", - }, - indent = { enable = true }, - ignore_install = { - "txt", - "go" - }, - sync_install = false, - auto_install = true, - highlight = { - enable = true, - disable = function(_, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - additional_vim_regex_highlighting = false, - }, - parsers = { - html = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-vue", - files = { "src/parser.c" }, - branch = "main" - } - } - } - } - require 'nvim-treesitter'.setup(treesitter_opt) - require 'nvim-treesitter.install'.prefer_git = true - if G.use_ssh then - local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() - for _, p in pairs(parsers) do - p.install_info.url = p.install_info.url:gsub("https://github/com/", "git@github.com:") - end - end - end - }, - }, - { - 'fgheng/winbar.nvim', - config = function() - require('winbar').setup({ - enabled = true, -- 是否启动winbar - - -- show_file_path = true, -- 是否显示文件路径 - show_symbols = true, -- 是否显示函数标签 - - -- 颜色配置,为空,将使用默认配色 - colors = { - path = '#aaffff', -- 路径的颜色,比如#ababab - file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac - symbols = '#aaffaa', -- 函数颜色 - }, - - -- 图标配置 - icons = { - seperator = '>', -- 路径分割符号 - editor_state = '●', - lock_icon = '', - }, - - -- 关闭winbar的窗口 - exclude_filetype = { - 'help', - 'startify', - 'dashboard', - 'packer', - 'neogitstatus', - 'NvimTree', - 'Trouble', - 'alpha', - 'lir', - 'Outline', - 'spectre_panel', - 'toggleterm', - 'qf', - } }) end }, diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua index c2f2607..53b7149 100644 --- a/lua/plugs/nvimtree.lua +++ b/lua/plugs/nvimtree.lua @@ -1,10 +1,10 @@ return { "nvim-tree/nvim-tree.lua", dependencies = { - 'kyazdani42/nvim-web-devicons' + 'nvim-tree/nvim-web-devicons' }, keys = { - "" + { "", "NvimTreeToggle", desc = "Toggle file tree" } }, config = function() require 'nvim-web-devicons'.setup {} @@ -33,8 +33,5 @@ return { }) end } - G.map({ - { "n", "", ":NvimTreeToggle", { noremap = true } }, - }) end } diff --git a/lua/plugs/symbols-outline.lua b/lua/plugs/symbols-outline.lua new file mode 100644 index 0000000..3d481a9 --- /dev/null +++ b/lua/plugs/symbols-outline.lua @@ -0,0 +1,74 @@ +return { + { -- + 'simrat39/symbols-outline.nvim', + config = function() + local opts = { + highlight_hovered_item = true, + show_guides = true, + auto_preview = false, + position = 'right', + relative_width = true, + width = 25, + auto_close = false, + show_numbers = false, + show_relative_numbers = false, + show_symbol_details = true, + preview_bg_highlight = 'Pmenu', + autofold_depth = nil, + auto_unfold_hover = true, + fold_markers = { '', '' }, + wrap = false, + keymaps = { + close = { "", "q" }, + goto_location = "", + focus_location = "h", + hover_symbol = "", + toggle_preview = "K", + rename_symbol = "r", + code_actions = "a", + fold = "o", + unfold = "l", + fold_all = "W", + unfold_all = "E", + fold_reset = "R", + }, + lsp_blacklist = {}, + symbol_blacklist = {}, + symbols = { + File = { icon = "", hl = "@text.uri" }, + Module = { icon = "", hl = "@namespace" }, + Namespace = { icon = "", hl = "@namespace" }, + Package = { icon = "", hl = "@namespace" }, + Class = { icon = "𝓒", hl = "@type" }, + Method = { icon = "ƒ", hl = "@method" }, + Property = { icon = "", hl = "@method" }, + Field = { icon = "", hl = "@field" }, + Constructor = { icon = "", hl = "@constructor" }, + Enum = { icon = "ℰ", hl = "@type" }, + Interface = { icon = "ﰮ", hl = "@type" }, + Function = { icon = "", hl = "@function" }, + Variable = { icon = "", hl = "@constant" }, + Constant = { icon = "", hl = "@constant" }, + String = { icon = "𝓐", hl = "@string" }, + Number = { icon = "#", hl = "@number" }, + Boolean = { icon = "⊨", hl = "@boolean" }, + Array = { icon = "", hl = "@constant" }, + Object = { icon = "⦿", hl = "@type" }, + Key = { icon = "🔐", hl = "@type" }, + Null = { icon = "NULL", hl = "@type" }, + EnumMember = { icon = "", hl = "@field" }, + Struct = { icon = "𝓢", hl = "@type" }, + Event = { icon = "🗲", hl = "@type" }, + Operator = { icon = "+", hl = "@operator" }, + TypeParameter = { icon = "𝙏", hl = "@parameter" }, + Component = { icon = "", hl = "@function" }, + Fragment = { icon = "", hl = "@constant" }, + }, + } + require("symbols-outline").setup(opts) + G.map({ + { "n", "", "SymbolsOutline", { noremap = true } }, + }) + end + }, +} diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index 013bed5..15db832 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -7,8 +7,7 @@ return { end }, { - -- line插件 - 'kdheepak/tabline.nvim', + -- 状态栏 'nvim-lualine/lualine.nvim', config = function() require('lualine').setup { @@ -17,17 +16,13 @@ return { theme = 'auto', component_separators = { left = '', right = '' }, section_separators = { left = '', right = '' }, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, ignore_focus = {}, always_divide_middle = true, globalstatus = false, refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, + statusline = 2000, + tabline = 2000, + winbar = 2000, } }, sections = { @@ -50,33 +45,32 @@ return { lualine_y = {}, lualine_z = {} }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} - } - require('tabline').setup { - -- Defaults configuration options - enable = true, - options = { - -- If lualine is installed tabline will use separators configured in lualine by default. - -- These options can be used to override those settings. - section_separators = { ' ', ' ' }, - component_separators = { '', '' }, - max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 - show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named - show_devicons = true, -- this shows devicons in buffer section - show_bufnr = false, -- this appends [bufnr] to buffer section, - show_filename_only = true, -- shows base filename only instead of relative path in filename - modified_icon = "+ ", -- change the default modified icon - modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified - show_tabs_only = false, -- this shows only tabs instead of tabs + buffers - }, - G.cmd [[ - set guioptions-=e " Use showtabline in gui vim - set sessionoptions+=tabpages,globals " store tabpages and globals in session - ]] } end, }, + { + -- 标签栏 + 'kdheepak/tabline.nvim', + config = function() + require('tabline').setup { + enable = true, + options = { + section_separators = { ' ', ' ' }, + component_separators = { '', '' }, + max_bufferline_percent = 66, + show_tabs_always = false, + show_devicons = true, + show_bufnr = false, + show_filename_only = true, + modified_icon = "+ ", + modified_italic = false, + show_tabs_only = false, + }, + } + G.cmd [[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session + ]] + end, + }, } diff --git a/lua/plugs/treesitter.lua b/lua/plugs/treesitter.lua new file mode 100644 index 0000000..d4a0f56 --- /dev/null +++ b/lua/plugs/treesitter.lua @@ -0,0 +1,46 @@ +return { + { + -- 语法高亮:auto_install=true 自动装 parser,ignore_install 跳过 txt + 'nvim-treesitter/nvim-treesitter', + config = function() + local treesitter_opt = { + indent = { enable = true }, + ignore_install = { + "txt" + }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + -- 大于 100KB 的文件关闭 treesitter 高亮(性能优化) + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, + -- 自定义 Vue parser:上游 tree-sitter-html 不识别 .vue 单文件组件 + parsers = { + vue = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c" }, + branch = "main", + }, + }, + }, + } + require 'nvim-treesitter'.setup(treesitter_opt) + require 'nvim-treesitter.install'.prefer_git = true + if G.use_ssh then + local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() + for _, p in pairs(parsers) do + p.install_info.url = p.install_info.url:gsub("https://github.com/", "git@github.com:") + end + end + end + }, +} diff --git a/lua/plugs/winbar.lua b/lua/plugs/winbar.lua new file mode 100644 index 0000000..3403186 --- /dev/null +++ b/lua/plugs/winbar.lua @@ -0,0 +1,40 @@ +return { + { + 'fgheng/winbar.nvim', + config = function() + require('winbar').setup({ + enabled = true, + + show_symbols = true, + + colors = { + path = '#aaffff', + file_name = '#bbbbff', + symbols = '#aaffaa', + }, + + icons = { + separator = '>', + editor_state = '●', + lock_icon = '', + }, + + exclude_filetype = { + 'help', + 'startify', + 'dashboard', + 'packer', + 'neogitstatus', + 'NvimTree', + 'Trouble', + 'alpha', + 'lir', + 'Outline', + 'spectre_panel', + 'toggleterm', + 'qf', + } + }) + end + }, +} diff --git a/lua/vsc.lua b/lua/vsc.lua index 0abf89d..f76df1f 100644 --- a/lua/vsc.lua +++ b/lua/vsc.lua @@ -1,4 +1,3 @@ require 'lazy'.setup({ require('plugs.edit-plugs'), - -- 'vijaymarupudi/nvim-fzf', -- fzf }) diff --git a/snippets/lua.json b/snippets/lua.json index 0db3279..21c64a7 100644 --- a/snippets/lua.json +++ b/snippets/lua.json @@ -1,3 +1,91 @@ { - + "plug": { + "prefix": "plug", + "body": [ + "{", + " '${1:owner/repo}',", + " config = function()", + " require('${2}').setup({$3})", + " end,", + "}," + ] + }, + "plugkey": { + "prefix": "plugkey", + "body": [ + "{", + " '${1:owner/repo}',", + " keys = { '${2}' },", + " config = function()", + " require('${3}').setup({$4})", + " end,", + "}," + ] + }, + "plugftp": { + "prefix": "plugftp", + "body": [ + "{", + " '${1:owner/repo}',", + " ft = { '${2}' },", + " config = function()", + " require('${3}').setup({$4})", + " end,", + "}," + ] + }, + "map": { + "prefix": "map", + "body": "{ '${1:n}', '${2:}', '${3:cmd}', { noremap = true } }," + }, + "mapl": { + "prefix": "mapl", + "body": [ + "{ '${1:n}', '${2:}',", + " function()", + " ${3}", + " end,", + " { noremap = true }", + "}," + ] + }, + "func": { + "prefix": "func", + "body": [ + "function ${1:name}(${2:args})", + " ${3}", + "end" + ] + }, + "localf": { + "prefix": "localf", + "body": [ + "local ${1:name} = function(${2:args})", + " ${3}", + "end" + ] + }, + "Gmap": { + "prefix": "Gmap", + "body": [ + "G.map({", + " { '${1:n}', '${2:}', '${3:cmd}', { noremap = true } },", + "})" + ] + }, + "req": { + "prefix": "req", + "body": "local ${1:name} = require('${1}')" + }, + "au": { + "prefix": "au", + "body": [ + "G.au({ '${1:BufEnter}' }, {", + " pattern = { '${2:*}' },", + " callback = function()", + " ${3}", + " end,", + "})" + ] + } }