From e1614703fdf2b0102f3110a94aad479d1d4c928c Mon Sep 17 00:00:00 2001 From: maye Date: Mon, 30 Jun 2025 11:38:20 +0800 Subject: [PATCH] update --- .gitignore | 1 + init.lua | 1 + lazy-lock.json | 19 ++++++----- lua/commons/init.lua | 1 + lua/configs/autocmds.lua | 41 ++++++++++++++++++++++++ lua/configs/mappings.lua | 7 +++++ lua/functions/lsp.lua | 16 +++++----- lua/plugins/bufferline.lua | 20 ++++++++++++ lua/plugins/lspconfig.lua | 2 +- lua/plugins/neo-tree.lua | 64 -------------------------------------- lua/plugins/snacks.lua | 13 +++++--- 11 files changed, 96 insertions(+), 89 deletions(-) create mode 100644 .gitignore create mode 100644 lua/configs/autocmds.lua create mode 100644 lua/plugins/bufferline.lua delete mode 100644 lua/plugins/neo-tree.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0ac3ed --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.aider* diff --git a/init.lua b/init.lua index f54fdee..d5ad347 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,4 @@ require('configs.options') require('configs.mappings') require('configs.lazy') +require('configs.autocmds') diff --git a/lazy-lock.json b/lazy-lock.json index 14ba61e..612cf7d 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,23 +1,22 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, "blink.cmp": { "branch": "main", "commit": "022521a8910a5543b0251b21c9e1a1e989745796" }, - "conform.nvim": { "branch": "master", "commit": "a4bb5d6c4ae6f32ab13114e62e70669fa67745b9" }, + "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, + "conform.nvim": { "branch": "master", "commit": "6feb2f28f9a9385e401857b21eeac3c1b66dd628" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, - "fzf-lua": { "branch": "main", "commit": "8adf950093af5361621cf52208d64995b1af78b5" }, - "gitsigns.nvim": { "branch": "main", "commit": "ee0606259ee5d5dd40398be26755048e8965086e" }, + "fzf-lua": { "branch": "main", "commit": "97f665a38d73a6541d98b542c79b4bead8e85d4c" }, + "gitsigns.nvim": { "branch": "main", "commit": "8b729e489f1475615dc6c9737da917b3bc163605" }, "gruvbox.nvim": { "branch": "main", "commit": "00e38a379bab3389e187b3953566d67d494dfddd" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lualine.nvim": { "branch": "master", "commit": "ecfcfee812ef4fee1e86ae8f315c4a045f7da719" }, - "mason.nvim": { "branch": "main", "commit": "9eaedb864cdadc29c6eb7d761a6c0d8aee26c91b" }, - "neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" }, - "nui.nvim": { "branch": "main", "commit": "f535005e6ad1016383f24e39559833759453564e" }, + "lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" }, + "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-lspconfig": { "branch": "master", "commit": "ac1dfbe3b60e5e23a2cff90e3bd6a3bc88031a57" }, - "nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" }, + "nvim-lspconfig": { "branch": "master", "commit": "3ea99227e316c5028f57a4d86a1a7fd01dd876d0" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "snacks.nvim": { "branch": "main", "commit": "bc0630e43be5699bb94dadc302c0d21615421d93" }, - "tiny-code-action.nvim": { "branch": "main", "commit": "dc0bcd1420124dfd82e625f28caee5a825ffa317" }, + "tiny-code-action.nvim": { "branch": "main", "commit": "6bfecd218c617e125e69731033fb0d695b8b5144" }, "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } } diff --git a/lua/commons/init.lua b/lua/commons/init.lua index 5eea63c..585cfd2 100644 --- a/lua/commons/init.lua +++ b/lua/commons/init.lua @@ -10,6 +10,7 @@ local M = { "pyright", "yamlls", "ts_ls", + "rust-analyzer", }, tools = { is_version_gte_0_11 = function() diff --git a/lua/configs/autocmds.lua b/lua/configs/autocmds.lua new file mode 100644 index 0000000..fc73dfe --- /dev/null +++ b/lua/configs/autocmds.lua @@ -0,0 +1,41 @@ +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd + +autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank({ + higroup = "IncSearch", + timeout = 1000, + }) + end, +}) + +-- Remove whitespace on save. +autocmd("BufWritePre", { + pattern = "", + command = ":%s/\\s\\+$//e", +}) + +-- Do not auto comment new line. +autocmd("BufEnter", { + pattern = "", + command = "set fo-=c fo-=r fo-=o", +}) + +autocmd("Filetype", { + pattern = { "xml", "html", "xhtml", "css", "scss", "javascript", "typescript", "yaml", "sshconfig" }, + command = "setlocal shiftwidth=2 tabstop=2", +}) + +autocmd("Filetype", { + pattern = { "python", "rst", "rs", "c", "cpp", "go", "java" }, + command = "set colorcolumn=80", +}) + +autocmd("Filetype", { + pattern = { "gitcommit", "markdown", "text" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) diff --git a/lua/configs/mappings.lua b/lua/configs/mappings.lua index 472bb8d..bd35a72 100644 --- a/lua/configs/mappings.lua +++ b/lua/configs/mappings.lua @@ -1,2 +1,9 @@ local map = vim.keymap.set map("n", "s", ":w", {}) +map("n", "q", ":bdelete", {}) +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 }) diff --git a/lua/functions/lsp.lua b/lua/functions/lsp.lua index 4c67720..c88454f 100644 --- a/lua/functions/lsp.lua +++ b/lua/functions/lsp.lua @@ -1,14 +1,12 @@ local lspconfig = require("lspconfig") if require("commons").tools.is_version_gte_0_11() then --- vim.lsp.config("*", { --- capabilities = require("blink.cmp").get_lsp_capabilities(), --- root_markers = { ".git" }, --- }) + vim.lsp.config("*", { + capabilities = require("blink.cmp").get_lsp_capabilities(), + root_markers = { ".git" }, + }) for _, server in pairs(require("commons").servers) do local ok, settings = pcall(require, "lsp." .. server) - if ok then - vim.lsp.config(server, settings) - end + if ok then vim.lsp.config(server, settings) end vim.lsp.enable(server) end vim.diagnostic.config({ @@ -18,11 +16,11 @@ if require("commons").tools.is_version_gte_0_11() then virtual_text = true, }) else - local capabilities = require('blink.cmp').get_lsp_capabilities() + local capabilities = require("blink.cmp").get_lsp_capabilities() for _, server in pairs(require("commons").servers) do local ok, settings = pcall(require, "lsp." .. server) if ok then - settings.capabilities = capabilities + settings.capabilities = capabilities lspconfig[server].setup(settings) end end diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..391a1cd --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,20 @@ +return { + "akinsho/bufferline.nvim", + version = "*", + dependencies = "nvim-tree/nvim-web-devicons", + config = function(_,opts) + require("bufferline").setup({ + options = { + close_command = "bdelete! %d", + right_mouse_command = "bdelete! %d", + offsets = { + { + filetype = "snacks_layout_box", + text = "Snacks File Picker", + separator = true, + } + } + } + }) + end, +} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index 0133361..5e9dfb0 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -1,6 +1,6 @@ return { "neovim/nvim-lspconfig", - event = "InsertEnter", + -- event = "InsertEnter", -- cond = not require("commons").tools.is_version_gte_0_11(), dependencies = { { "saghen/blink.cmp" }, { "williamboman/mason.nvim" } }, config = function() diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua deleted file mode 100644 index a53a14c..0000000 --- a/lua/plugins/neo-tree.lua +++ /dev/null @@ -1,64 +0,0 @@ -return { - "nvim-neo-tree/neo-tree.nvim", - branch = "v3.x", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-tree/nvim-web-devicons", - "MunifTanjim/nui.nvim", - }, - cmd = "Neotree", - keys = { - { - "n", - function() require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) end, - desc = "Explorer NeoTree", - }, - { - "ge", - function() require("nvim-tree.command").exceute({ source = "git_status", toggle = true }) end, - desc = "Git Explorer", - }, - }, - init = function() - vim.api.nvim_create_autocmd("BufEnter", { - group = vim.api.nvim_create_augroup("Neotree_start_directory", { clear = true }), - desc = "Start Neo-Tree with directory", - once = true, - callback = function() - if package.loaded["neo-tree"] then - return - else - local stats = vim.uv.fs_stat(vim.fn.argv(0)) - if stats and stats.type == "directory" then require("neo-tree") end - end - end, - }) - end, - ---@module "neo-tree" - ---@type neotree.Config? - opts = { - sources = { "filesystem", "buffers", "git_status" }, - open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, - filesystem = { - bind_to_cwd = false, - follow_current_file = { enabled = true }, - use_libuv_file_watcher = true, - }, - window = { - mappings = { - ["l"] = "open", - ["h"] = "close_node", - [""] = "none", - ["Y"] = { - function(state) - local node = state.tree:get_node() - local path = node:get_id() - vim.fn.setreg("+", path, "c") - end, - desc = "Copy Path to Clipboard", - }, - }, - }, - }, - config = function(_, opts) require("neo-tree").setup(opts) end, -} diff --git a/lua/plugins/snacks.lua b/lua/plugins/snacks.lua index 7d0e5a4..2781244 100644 --- a/lua/plugins/snacks.lua +++ b/lua/plugins/snacks.lua @@ -4,26 +4,25 @@ return { lazy = false, ---@type snacks.Config opts = { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below bigfile = { enabled = true }, dashboard = { enabled = true }, - explorer = { enabled = true }, + explorer = { enabled = true, auto_close = true }, indent = { enabled = false }, input = { enabled = true }, picker = { enabled = true }, notifier = { enabled = true }, quickfile = { enabled = true }, scope = { enabled = true }, - scroll = { enabled = true }, + scroll = { enabled = false }, statuscolumn = { enabled = true }, words = { enabled = false }, }, keys = { + { "e", function() Snacks.explorer() end, desc = "Snack File Explorer" }, { "", function() Snacks.picker.smart() end, desc = "Smart Find Files" }, { "fg", function() Snacks.picker.git_files() end, desc = "Find Git Files" }, { "fp", function() Snacks.picker.projects() end, desc = "Projects" }, + { "n", function() Snacks.picker.notifications() end, desc = "Show history notifications" }, -- git { "gb", function() Snacks.picker.git_branches() end, desc = "Git Branches" }, { "gl", function() Snacks.picker.git_log() end, desc = "Git Log" }, @@ -32,6 +31,8 @@ return { { "gS", function() Snacks.picker.git_stash() end, desc = "Git Stash" }, { "gd", function() Snacks.picker.git_diff() end, desc = "Git Diff (Hunks)" }, { "gf", function() Snacks.picker.git_log_file() end, desc = "Git Log File" }, + { "gB", function() Snacks.gitbrowse() end, desc = "Git Browse", mode = { "n", "v" } }, + { "gg", function() Snacks.lazygit() end, desc = "Lazygit" }, -- Grep { "sb", function() Snacks.picker.lines() end, desc = "Buffer Lines" }, { "sB", function() Snacks.picker.grep_buffers() end, desc = "Grep Open Buffers" }, @@ -54,5 +55,7 @@ return { { "]]", function() Snacks.words.jump(vim.v.count1) end, desc = "Next Reference", mode = { "n", "t" } }, { "[[", function() Snacks.words.jump(-vim.v.count1) end, desc = "Prev Reference", mode = { "n", "t" } }, { "", function() Snacks.terminal() end, desc = "Toggle Terminal" }, + { ".", function() Snacks.scratch() end, desc = "Toggle Scratch Buffer" }, + { "S", function() Snacks.scratch.select() end, desc = "Select Scratch Buffer" }, }, }