From 631e88bdd2766396ed6f6ee9d1ceb2a7e16d9420 Mon Sep 17 00:00:00 2001 From: cedricreper Date: Fri, 17 Oct 2025 15:04:25 +0900 Subject: [PATCH] refactor --- CLAUDE.md | 75 +++++----- lua/plugins/autopairs.lua | 9 ++ lua/plugins/flash.lua | 16 +++ lua/plugins/{utils.lua => gitsigns.lua} | 15 -- lua/plugins/{navigation.lua => harpoon.lua} | 48 ------- lua/plugins/lualine.lua | 11 ++ lua/plugins/oil.lua | 18 +++ lua/plugins/optional/README.md | 33 ----- lua/plugins/optional/debug.lua | 149 -------------------- lua/plugins/optional/indent-blankline.lua | 11 -- lua/plugins/optional/lint.lua | 63 --------- lua/plugins/snacks.lua | 7 + lua/plugins/vim-sleuth.lua | 4 + lua/plugins/vim-tmux-navigator.lua | 20 +++ lua/plugins/{ui.lua => which-key.lua} | 9 -- 15 files changed, 122 insertions(+), 366 deletions(-) create mode 100644 lua/plugins/autopairs.lua create mode 100644 lua/plugins/flash.lua rename lua/plugins/{utils.lua => gitsigns.lua} (86%) rename lua/plugins/{navigation.lua => harpoon.lua} (54%) create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/oil.lua delete mode 100644 lua/plugins/optional/README.md delete mode 100644 lua/plugins/optional/debug.lua delete mode 100644 lua/plugins/optional/indent-blankline.lua delete mode 100644 lua/plugins/optional/lint.lua create mode 100644 lua/plugins/snacks.lua create mode 100644 lua/plugins/vim-sleuth.lua create mode 100644 lua/plugins/vim-tmux-navigator.lua rename lua/plugins/{ui.lua => which-key.lua} (64%) diff --git a/CLAUDE.md b/CLAUDE.md index ba6f0849..afdfdff2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,16 +21,23 @@ The configuration is organized into three main directories: │ │ ├── keymaps.lua # Global key mappings │ │ └── autocommands.lua # Autocommands (highlight on yank, etc.) │ ├── plugins/ # Plugin specifications (auto-loaded by lazy.nvim) -│ │ ├── colorscheme.lua # Color scheme (kanso.nvim + alternatives) -│ │ ├── treesitter.lua # Syntax highlighting & parsing -│ │ ├── lsp.lua # LSP configuration & Mason -│ │ ├── completion.lua # blink.cmp & LuaSnip -│ │ ├── telescope.lua # Fuzzy finder -│ │ ├── navigation.lua # Harpoon, Flash, Oil, tmux-navigator -│ │ ├── formatting.lua # conform.nvim -│ │ ├── ui.lua # which-key, lualine -│ │ ├── utils.lua # vim-sleuth, gitsigns, autopairs, snacks +│ │ ├── autopairs.lua # Auto-close brackets and quotes │ │ ├── claude-code.lua # Claude Code integration +│ │ ├── colorscheme.lua # Color scheme (kanso.nvim + alternatives) +│ │ ├── completion.lua # blink.cmp & LuaSnip +│ │ ├── flash.lua # Rapid cursor movement +│ │ ├── formatting.lua # conform.nvim for code formatting +│ │ ├── gitsigns.lua # Git signs and operations +│ │ ├── harpoon.lua # File bookmarking +│ │ ├── lsp.lua # LSP configuration & Mason +│ │ ├── lualine.lua # Status line +│ │ ├── oil.lua # File browser +│ │ ├── snacks.lua # Utility plugin +│ │ ├── telescope.lua # Fuzzy finder +│ │ ├── treesitter.lua # Syntax highlighting & parsing +│ │ ├── vim-sleuth.lua # Auto-detect indentation +│ │ ├── vim-tmux-navigator.lua # Tmux/Vim navigation +│ │ ├── which-key.lua # Keybinding hints │ │ └── optional/ # Optional plugins (not loaded by default) │ │ ├── README.md # Instructions for enabling optional plugins │ │ ├── debug.lua # DAP debugger for Go @@ -46,34 +53,26 @@ The configuration is organized into three main directories: - **Auto-Loading**: All files in `lua/plugins/*.lua` are automatically loaded - **Custom Plugins**: Add your own in `lua/custom/plugins/init.lua` or create new files there -### Key Plugin Categories +### Key Plugins -1. **LSP Configuration** (`lua/plugins/lsp.lua`) - - Mason for LSP installation - - Configured servers: `pyright`, `zls`, `rust_analyzer`, `ts_ls`, `lua_ls` - - LSP capabilities enhanced by blink.cmp - - Autocommands for LSP attach events setup keymaps and highlighting +Each plugin is in its own file for easy management: -2. **Completion** (`lua/plugins/completion.lua`) - - blink.cmp for autocompletion - - LuaSnip for snippet expansion - - Default keymap preset uses `` to accept - -3. **Telescope** (`lua/plugins/telescope.lua`) - - Fuzzy finder with vertical layout - - Extensions: fzf, ui-select - - Leader-based keymaps for searching files, grep, diagnostics, etc. - -4. **Navigation & Movement** (`lua/plugins/navigation.lua`) - - Harpoon2 for file bookmarking - - Flash.nvim for rapid cursor movement - - Oil.nvim for file browsing - - vim-tmux-navigator for seamless tmux/vim navigation - -5. **Formatting** (`lua/plugins/formatting.lua`) - - conform.nvim handles formatting - - Format on save enabled (except for C/C++) - - Configured formatters: stylua (Lua), prettier (JS/TS/CSS/HTML/JSON) +- **lsp.lua** - LSP configuration with Mason, servers: `pyright`, `zls`, `rust_analyzer`, `ts_ls`, `lua_ls` +- **completion.lua** - blink.cmp autocompletion with LuaSnip snippets +- **telescope.lua** - Fuzzy finder with vertical layout, fzf and ui-select extensions +- **harpoon.lua** - Quick file bookmarking and navigation +- **flash.lua** - Rapid cursor movement with `s`, `S`, `r`, `R` keys +- **oil.lua** - File browser with `-` key binding +- **vim-tmux-navigator.lua** - Seamless tmux/vim split navigation +- **formatting.lua** - conform.nvim with format-on-save (stylua, prettier) +- **gitsigns.lua** - Git signs in gutter with staging/diffing keymaps +- **which-key.lua** - Keybinding hints popup +- **lualine.lua** - Status line with base16 theme +- **treesitter.lua** - Syntax highlighting for multiple languages +- **autopairs.lua** - Auto-close brackets and quotes +- **vim-sleuth.lua** - Auto-detect indentation +- **snacks.lua** - Utility plugin collection +- **colorscheme.lua** - Multiple color schemes (kanso active) ## Common Commands @@ -205,9 +204,9 @@ Currently using kanso.nvim. Several commented-out alternatives available (gruvbo ### Plugin Organization Philosophy -- **Separation by Function**: Each file in `lua/plugins/` represents a logical category -- **Easy Discovery**: Find all plugins of a type in one file -- **Modular**: Add/remove entire categories by managing single files +- **One Plugin Per File**: Each plugin has its own dedicated file in `lua/plugins/` (except colorscheme.lua which contains theme options) +- **Easy Discovery**: Plugin files are named after the plugin they configure +- **Modular**: Add/remove individual plugins by managing single files - **Custom Additions**: Use `lua/custom/plugins/` for your personal plugins without modifying core structure ### Optional Plugins diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 00000000..1f06baee --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,9 @@ +return { + { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + config = true, + -- use opts = {} for passing setup options + -- this is equivalent to setup({}) function + }, +} diff --git a/lua/plugins/flash.lua b/lua/plugins/flash.lua new file mode 100644 index 00000000..047f75c2 --- /dev/null +++ b/lua/plugins/flash.lua @@ -0,0 +1,16 @@ +return { + { + 'folke/flash.nvim', + event = 'VeryLazy', + ---@type Flash.Config + opts = {}, + -- stylua: ignore + keys = { + { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, + { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + }, + }, +} diff --git a/lua/plugins/utils.lua b/lua/plugins/gitsigns.lua similarity index 86% rename from lua/plugins/utils.lua rename to lua/plugins/gitsigns.lua index b7e3b1d2..7f2dee71 100644 --- a/lua/plugins/utils.lua +++ b/lua/plugins/gitsigns.lua @@ -1,7 +1,4 @@ return { - -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically - { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', opts = { @@ -64,16 +61,4 @@ return { end, }, }, - { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - config = true, - -- use opts = {} for passing setup options - -- this is equivalent to setup({}) function - }, - { - 'folke/snacks.nvim', - priority = 1000, - lazy = false, - }, } diff --git a/lua/plugins/navigation.lua b/lua/plugins/harpoon.lua similarity index 54% rename from lua/plugins/navigation.lua rename to lua/plugins/harpoon.lua index acae343e..a21ed5ff 100644 --- a/lua/plugins/navigation.lua +++ b/lua/plugins/harpoon.lua @@ -1,36 +1,4 @@ return { - { - 'christoomey/vim-tmux-navigator', - cmd = { - 'TmuxNavigateLeft', - 'TmuxNavigateDown', - 'TmuxNavigateUp', - 'TmuxNavigateRight', - 'TmuxNavigatePrevious', - 'TmuxNavigatorProcessList', - }, - keys = { - { '', 'TmuxNavigateLeft' }, - { '', 'TmuxNavigateDown' }, - { '', 'TmuxNavigateUp' }, - { '', 'TmuxNavigateRight' }, - { '', 'TmuxNavigatePrevious' }, - }, - }, - { - 'folke/flash.nvim', - event = 'VeryLazy', - ---@type Flash.Config - opts = {}, - -- stylua: ignore - keys = { - { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, - { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, - }, - }, { 'ThePrimeagen/harpoon', branch = 'harpoon2', @@ -91,20 +59,4 @@ return { end, { desc = 'Open harpoon window' }) end, }, - { - 'stevearc/oil.nvim', - ---@module 'oil' - ---@type oil.SetupOpts - opts = {}, - -- Optional dependencies - dependencies = { { 'echasnovski/mini.icons', opts = {} } }, - -- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if you prefer nvim-web-devicons - -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. - lazy = false, - config = function() - require('oil').setup { - vim.keymap.set('n', '-', 'Oil', { desc = 'Open parent directory' }), - } - end, - }, } diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 00000000..800aaab8 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,11 @@ +return { + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup { + theme = 'base16', + } + end, + }, +} diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua new file mode 100644 index 00000000..17ee9009 --- /dev/null +++ b/lua/plugins/oil.lua @@ -0,0 +1,18 @@ +return { + { + 'stevearc/oil.nvim', + ---@module 'oil' + ---@type oil.SetupOpts + opts = {}, + -- Optional dependencies + dependencies = { { 'echasnovski/mini.icons', opts = {} } }, + -- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if you prefer nvim-web-devicons + -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. + lazy = false, + config = function() + require('oil').setup { + vim.keymap.set('n', '-', 'Oil', { desc = 'Open parent directory' }), + } + end, + }, +} diff --git a/lua/plugins/optional/README.md b/lua/plugins/optional/README.md deleted file mode 100644 index 1ed84429..00000000 --- a/lua/plugins/optional/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Optional Plugins - -These are optional plugins that are not enabled by default but may be useful for certain workflows. - -## How to Enable - -To enable an optional plugin, simply move it from `lua/plugins/optional/` to `lua/plugins/` and restart Neovim. - -For example: -```bash -mv lua/plugins/optional/debug.lua lua/plugins/debug.lua -``` - -Or create a symlink: -```bash -ln -s optional/debug.lua lua/plugins/debug.lua -``` - -## Available Optional Plugins - -- **indent-blankline.lua** - Adds indentation guides on blank lines -- **debug.lua** - DAP debugger for Go (and extensible to other languages) -- **lint.lua** - Linting with nvim-lint (markdown example included) - -## Alternative Approach - -You can also import these directly by adding to your `init.lua`: -```lua -require('lazy').setup({ - { import = 'plugins' }, - { import = 'plugins.optional.debug' }, -- Enable debug plugin -}) -``` diff --git a/lua/plugins/optional/debug.lua b/lua/plugins/optional/debug.lua deleted file mode 100644 index 0c175a6f..00000000 --- a/lua/plugins/optional/debug.lua +++ /dev/null @@ -1,149 +0,0 @@ --- debug.lua --- --- DAP (Debug Adapter Protocol) plugin for debugging your code. --- To enable: move this file to lua/plugins/ or import it in init.lua --- --- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. --- See `:help dap` for more information - -return { - -- NOTE: Yes, you can install new plugins here! - 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well - dependencies = { - -- Creates a beautiful debugger UI - 'rcarriga/nvim-dap-ui', - - -- Required dependency for nvim-dap-ui - 'nvim-neotest/nvim-nio', - - -- Installs the debug adapters for you - 'williamboman/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', - - -- Add your own debuggers here - 'leoluz/nvim-dap-go', - }, - keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - '', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - { - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - 'b', - function() - require('dap').toggle_breakpoint() - end, - desc = 'Debug: Toggle Breakpoint', - }, - { - 'B', - function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, - desc = 'Debug: Set Breakpoint', - }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, - }, - config = function() - local dap = require 'dap' - local dapui = require 'dapui' - - require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, - - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information - handlers = {}, - - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - 'delve', - }, - } - - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', - }, - }, - } - - -- Change breakpoint icons - -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) - -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) - -- local breakpoint_icons = vim.g.have_nerd_font - -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } - -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } - -- for type, icon in pairs(breakpoint_icons) do - -- local tp = 'Dap' .. type - -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' - -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) - -- end - - dap.listeners.after.event_initialized['dapui_config'] = dapui.open - dap.listeners.before.event_terminated['dapui_config'] = dapui.close - dap.listeners.before.event_exited['dapui_config'] = dapui.close - - -- Install golang specific config - require('dap-go').setup { - delve = { - -- On Windows delve must be run attached or it crashes. - -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring - detached = vim.fn.has 'win32' == 0, - }, - } - end, -} diff --git a/lua/plugins/optional/indent-blankline.lua b/lua/plugins/optional/indent-blankline.lua deleted file mode 100644 index 5b278ca6..00000000 --- a/lua/plugins/optional/indent-blankline.lua +++ /dev/null @@ -1,11 +0,0 @@ --- Adds indentation guides even on blank lines --- To enable: move this file to lua/plugins/ or import it in init.lua --- See `:help ibl` - -return { - { - 'lukas-reineke/indent-blankline.nvim', - main = 'ibl', - opts = {}, - }, -} diff --git a/lua/plugins/optional/lint.lua b/lua/plugins/optional/lint.lua deleted file mode 100644 index 83574f57..00000000 --- a/lua/plugins/optional/lint.lua +++ /dev/null @@ -1,63 +0,0 @@ --- Linting with nvim-lint --- To enable: move this file to lua/plugins/ or import it in init.lua --- See `:help lint` for more information - -return { - { -- Linting - 'mfussenegger/nvim-lint', - event = { 'BufReadPre', 'BufNewFile' }, - config = function() - local lint = require 'lint' - lint.linters_by_ft = { - markdown = { 'markdownlint' }, - } - - -- To allow other plugins to add linters to require('lint').linters_by_ft, - -- instead set linters_by_ft like this: - -- lint.linters_by_ft = lint.linters_by_ft or {} - -- lint.linters_by_ft['markdown'] = { 'markdownlint' } - -- - -- However, note that this will enable a set of default linters, - -- which will cause errors unless these tools are available: - -- { - -- clojure = { "clj-kondo" }, - -- dockerfile = { "hadolint" }, - -- inko = { "inko" }, - -- janet = { "janet" }, - -- json = { "jsonlint" }, - -- markdown = { "vale" }, - -- rst = { "vale" }, - -- ruby = { "ruby" }, - -- terraform = { "tflint" }, - -- text = { "vale" } - -- } - -- - -- You can disable the default linters by setting their filetypes to nil: - -- lint.linters_by_ft['clojure'] = nil - -- lint.linters_by_ft['dockerfile'] = nil - -- lint.linters_by_ft['inko'] = nil - -- lint.linters_by_ft['janet'] = nil - -- lint.linters_by_ft['json'] = nil - -- lint.linters_by_ft['markdown'] = nil - -- lint.linters_by_ft['rst'] = nil - -- lint.linters_by_ft['ruby'] = nil - -- lint.linters_by_ft['terraform'] = nil - -- lint.linters_by_ft['text'] = nil - - -- Create autocommand which carries out the actual linting - -- on the specified events. - local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) - vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { - group = lint_augroup, - callback = function() - -- Only run the linter in buffers that you can modify in order to - -- avoid superfluous noise, notably within the handy LSP pop-ups that - -- describe the hovered symbol using Markdown. - if vim.opt_local.modifiable:get() then - lint.try_lint() - end - end, - }) - end, - }, -} diff --git a/lua/plugins/snacks.lua b/lua/plugins/snacks.lua new file mode 100644 index 00000000..99a56f7c --- /dev/null +++ b/lua/plugins/snacks.lua @@ -0,0 +1,7 @@ +return { + { + 'folke/snacks.nvim', + priority = 1000, + lazy = false, + }, +} diff --git a/lua/plugins/vim-sleuth.lua b/lua/plugins/vim-sleuth.lua new file mode 100644 index 00000000..d9a08871 --- /dev/null +++ b/lua/plugins/vim-sleuth.lua @@ -0,0 +1,4 @@ +-- Detect tabstop and shiftwidth automatically +return { + 'tpope/vim-sleuth', +} diff --git a/lua/plugins/vim-tmux-navigator.lua b/lua/plugins/vim-tmux-navigator.lua new file mode 100644 index 00000000..53f0523a --- /dev/null +++ b/lua/plugins/vim-tmux-navigator.lua @@ -0,0 +1,20 @@ +return { + { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateLeft', + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + 'TmuxNavigatorProcessList', + }, + keys = { + { '', 'TmuxNavigateLeft' }, + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, + }, +} diff --git a/lua/plugins/ui.lua b/lua/plugins/which-key.lua similarity index 64% rename from lua/plugins/ui.lua rename to lua/plugins/which-key.lua index 4d5a0a02..904c4b01 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/which-key.lua @@ -9,13 +9,4 @@ return { delay = 0, }, }, - { - 'nvim-lualine/lualine.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' }, - config = function() - require('lualine').setup { - theme = 'base16', - } - end, - }, }