From 6efcb93d3d6e7a195ea2b54881539ad5f845f255 Mon Sep 17 00:00:00 2001 From: maye Date: Wed, 27 Aug 2025 16:32:18 +0800 Subject: [PATCH] feat: q exit --- CLAUDE.md | 7 +++++-- lua/configs/mappings.lua | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c37c711..d718df5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,6 +19,7 @@ This is a modern Neovim configuration built around the lazy.nvim plugin manager. - LSP servers are defined in `commons.servers` array - Server-specific settings live in `lua/lsp/{server}.lua` files - Uses blink.cmp for completion capabilities +- LSP servers supported: lua_ls, gopls, clangd, bashls, pyright, yamlls, ts_ls, rust_analyzer - Mason.nvim auto-installs: stylua, lua-language-server, gopls, pyright ### Plugin Architecture @@ -28,8 +29,9 @@ This is a modern Neovim configuration built around the lazy.nvim plugin manager. ### Formatting - Conform.nvim handles formatting with `ff` keybind -- Format-on-save enabled with 500ms timeout +- Format-on-save enabled with 500ms timeout, format command uses 3000ms timeout - Configured formatters: stylua (Lua), black (Python), rustfmt (Rust), prettier (JS), shfmt (shell) +- Stylua configured with `--collapse-simple-statement Always` ## Common Development Tasks @@ -46,10 +48,11 @@ This is a modern Neovim configuration built around the lazy.nvim plugin manager. ### Key Mappings - Leader key: `` - Save: `s` -- Buffer delete: `q` +- Smart buffer delete: `q` (switches to next buffer, or opens explorer if last buffer) - Quit: `qq` (force quit: `qqq`) - Format code: `ff` - Toggle comment: `mm` (normal/visual mode) +- Show diagnostics: `d` (uses Snacks picker) ### File Structure Conventions - Plugin configs: `lua/plugins/{plugin-name}.lua` diff --git a/lua/configs/mappings.lua b/lua/configs/mappings.lua index bd35a72..925092a 100644 --- a/lua/configs/mappings.lua +++ b/lua/configs/mappings.lua @@ -1,9 +1,37 @@ local map = vim.keymap.set map("n", "s", ":w", {}) -map("n", "q", ":bdelete", {}) +map("n", "q", function() + local buffers = vim.fn.getbufinfo({ buflisted = 1 }) + if #buffers <= 1 then + -- Check if explorer is already open + local explorer_win = nil + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + local ft = vim.api.nvim_get_option_value("filetype", { buf = buf }) + if ft == "snacks_picker_list" then + explorer_win = win + break + end + end + vim.cmd("bdelete") + if explorer_win then + -- Explorer is already open, just focus it + vim.api.nvim_set_current_win(explorer_win) + else + -- Explorer not open, open it + Snacks.explorer() + end + else + vim.cmd("bnext") + vim.cmd("bdelete #") + end +end, { desc = "Smart buffer delete" }) map("n", "qq", ":q'", {}) map("n", "qqq", ":qa!", {}) map("n", "s", ":w", {}) map("n", "mm", "gcc", { desc = "Toggle comment", remap = true }) map("v", "mm", "gc", { desc = "Toggle comment", remap = true }) + +-- Diagnostics +map("n", "d", function() Snacks.picker.diagnostics() end, { desc = "Show Diagnostics" })