From 395c58999363cd4bf0bf187658ce6ed6da35fda9 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 28 May 2026 17:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E7=BA=A7?= =?UTF-8?q?=20CLAUDE.md=20=E9=85=8D=E7=BD=AE=E6=96=87=E6=A1=A3=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E6=9F=A5=E6=89=BE=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20rg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 .claude/CLAUDE.md 项目配置文档 - 从 .gitignore 中移除 .claude/ 以纳入版本控制 - ff 改用 mini.pick.builtin.cli 配合 rg --files --hidden Co-Authored-By: Claude Opus 4.7 (1M context) --- .claude/CLAUDE.md | 159 ++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 1 - lua/pack.lua | 4 +- 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 .claude/CLAUDE.md diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md new file mode 100644 index 0000000..d412389 --- /dev/null +++ b/.claude/CLAUDE.md @@ -0,0 +1,159 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +This is a personal Neovim configuration (~/.config/nvim) targeting **Neovim 0.12+**. It uses Neovim's built-in `vim.pack` plugin management (available in 0.12+) rather than external plugin managers like lazy.nvim or packer.nvim. + +A custom lightweight lazy-loading framework lives in `lua/lazy.lua` that wraps `on_event`/`on_keys`/`load` to defer heavy module initialization until first use. + +## File Architecture + +``` +init.lua -- Entry point: disables built-in plugins, loads all core modules +lua/options.lua -- Global vim options, highlight groups, yank highlighting +lua/keymaps.lua -- Keymaps (leader = space), window/tab navigation, buffer mgmt +lua/autocmds.lua -- Autocmds: restore cursor position, comment continuation, fold setup +lua/usercmds.lua -- User commands: :PackAdd, :PackDel, :PackUpdate +lua/pack.lua -- Plugin declarations via vim.pack.add(), mini.starter dashboard, + -- lazy.on_keys/on_event bindings for all deferred plugins +lua/lazy.lua -- Custom lazy-loading primitives: load(), on_event(), on_keys() +lua/plugins/ + lsp.lua -- LSP config (nvim-lspconfig + mason), conform.nvim formatter + treesitter.lua -- Treesitter setup: deferred parser install, per-buffer attach + pick.lua -- mini.pick wrappers: buffer picker, filetype picker + git.lua -- Custom git utilities: hunk preview, blame line, fugitive keymaps +colors/ -- Catppuccin colorscheme variants (frappe, latte, macchiato, mocha) +nvim-pack-lock.json -- Lock file for vim.pack managed plugins +``` + +## Plugin Management + +Plugins are declared in `lua/pack.lua` via `vim.pack.add({ urls }, { load = false })` and tracked in `nvim-pack-lock.json`. + +Available commands: +- `:PackAdd user/repo` — add a new plugin +- `:PackDel plugin-name` — delete a plugin +- `:PackUpdate [plugin-name]` — update all or specific plugins + +Plugins are loaded lazily via the custom framework in `lua/lazy.lua`: +- **on_event**: triggered by autocmd (e.g., `InsertEnter`, `BufReadPost`, `VimEnter`) +- **on_keys**: triggered by keymap press (e.g., `ff`, `gg`) +- **load**: manual loading checked by `_loaded` flag + +Key lazy-loading points in `pack.lua`: +- `mini.completion` / `mini.snippets` — `InsertEnter` +- `mini.diff` / `mini.surround` — `BufReadPost` +- `treesitter` / `lsp` — `VimEnter` +- `mini.pick` / `mini.extra` — key trigger (`ff`, etc.) +- `vim-fugitive` — key trigger (`gg`) +- `conform.nvim` — `BufWritePre` + +## LSP and Formatting + +- **LSP**: nvim-lspconfig + mason. Enabled servers: html, cssls, gopls, vtsls, rust_analyzer, lua_ls, taplo, svelte, dartls, kotlin_lsp. +- **Formatting**: conform.nvim with format-on-save. Formatters by filetype: + - `lua` → stylua + - `go` → gofumpt, goimports + - `js/ts/json/css/html/md` → biome (if biome.json found) or prettier + - `toml` → taplo +- Toggle autoformat per-buffer: `vim.b[bufnr].autoformat = false` +- Toggle autoformat globally: `vim.g.autoformat = false` + +## Treesitter + +Configured in `lua/plugins/treesitter.lua`. Parsers are installed lazily via `vim.defer_fn` to avoid blocking startup. Treesitter highlighting is attached per-buffer on `FileType` via `vim.treesitter.start()`. + +## Key Leader Bindings (Space) + +Common bindings defined across files: + +**File pickers (mini.pick):** +- `ff` — find files +- `fw` — live grep +- `fa` — find all files (including hidden/ignored) +- `fh` — search help tags +- `fo` — recent files +- `fz` — current buffer lines +- `sk` — search keymaps +- `` — buffer picker (supports `` to delete) +- `ft` — filetype picker + +**File browser (mini.files):** +- `-` — open at current file's directory +- `_` — open at project root (git root) + +**Git:** +- `gg` — fugitive (fullscreen new tab) +- `gd` — git diff vertical split +- `ghp` — preview current hunk +- `ghb` — blame current line +- `gB` — blame entire file +- `gD` — file git history +- `sr` — search and replace (grug-far) + +**LSP & diagnostics:** +- `gd` / `gh` — go to definition / hover +- `ca` — code action +- `fm` — format buffer +- `df` — show line diagnostic float +- `ds` — diagnostic location list +- `]d` / `[d` — next / prev diagnostic +- `]e` / `[e` — next / prev error +- `]w` / `[w` — next / prev warning + +**Buffer management:** +- `x` — close current buffer +- `bn` — new buffer +- `bo` — close other buffers + +**Editing & search:** +- `ss` — global replace word under cursor +- `u` — undotree (builtin) +- `` — clear search highlight + +**Window & tab:** +- `` — navigate between windows +- `tc/tn/]/[` — tab close / new / next / prev + +**Terminal:** +- `tt` — open new terminal +- `` — exit terminal mode to normal mode + +**File operations:** +- `` — save file +- `` — copy entire file to clipboard +- `yp` — copy relative file path +- `yP` — copy absolute file path + +## Development / Validation + +Since this is a Neovim config, there is no traditional build or test suite. + +Validate configuration changes: +```bash +# Syntax check init.lua +nvim --headless -c 'lua dofile("init.lua")' -c 'qa!' + +# Check for Lua syntax errors in a specific module +nvim --headless -c 'lua require("pack")' -c 'qa!' + +# Runtime health check +nvim --headless -c 'checkhealth' -c 'qa!' +``` + +Check startup time after changes: +```bash +nvim --startuptime /tmp/startup.log +q +``` + +## Important Design Patterns + +1. **Startup performance is a priority**. Heavy modules (treesitter, LSP, mason) are deferred to `VimEnter` or later. Clipboard is set via `vim.schedule()` to avoid provider detection blocking. + +2. **Custom lazy-loading in `lua/lazy.lua`**. Do not confuse with the lazy.nvim plugin manager — this is a ~35-line custom module. When adding new plugins that should load lazily, use `lazy.on_event()` or `lazy.on_keys()`. + +3. **mini.nvim monorepo**. Most UI/functionality comes from the single `mini.nvim` package (starter, pick, extra, files, icons, notify, cmdline, completion, snippets, diff, surround). These are configured individually in `pack.lua` or on-demand. + +4. **Colorscheme**. The active colorscheme is `catppuccin-mocha`, defined in `colors/catppuccin-mocha.lua`. The `moonflyTransparent` variable is still set in `init.lua` for compatibility but the moonfly theme was removed. diff --git a/.gitignore b/.gitignore index 0ad715e..950a1c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .omc/ others/ -.claude/ diff --git a/lua/pack.lua b/lua/pack.lua index f64e35c..c540849 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -330,7 +330,9 @@ end, { desc = "诊断位置列表" }) -- 只在首次使用时 setup 一次。 -- ff :文件查找 lazy.on_keys("pick", "ff", "n", pick.load_pick, function() - require("mini.pick").builtin.files() + require("mini.pick").builtin.cli({ + command = { "rg", "--files", "--hidden", "--color=never" }, + }) end, { desc = "文件查找" }) -- fw :实时 grep(在项目中搜索文本)