From f4d7cfbd13da4312b931df17b6eecc5680a20388 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 16 Oct 2025 22:46:07 +0545 Subject: [PATCH] refactor(plugins): improve plugin configurations and add C/C++ formatting --- lua/plugins/coding.lua | 21 +++++++---- lua/plugins/editor.lua | 45 ++++------------------ lua/plugins/format.lua | 6 ++- lua/plugins/mini.lua | 19 +++++----- lua/plugins/ui.lua | 86 +++--------------------------------------- lua/plugins/util.lua | 20 +++++----- 6 files changed, 50 insertions(+), 147 deletions(-) diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index 6c7d5b0..8036279 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -2,18 +2,23 @@ return { -- auto pairs { 'windwp/nvim-autopairs', - enabled = false, event = 'InsertEnter', config = function() local npairs = require('nvim-autopairs') + local Rule = require('nvim-autopairs.rule') + local conds = require('nvim-autopairs.conds') - npairs.setup({ - check_ts = true, - enable_check_bracket_line = true, - fast_wrap = {}, - map_cr = true, - map_bs = true, - }) + npairs.setup() + + -- Autoclosing angle-brackets. + npairs.add_rule(Rule('<', '>', { + -- Avoid conflicts with nvim-ts-autotag. + '-html', + '-javascriptreact', + '-typescriptreact', + }):with_pair(conds.before_regex('%a+:?:?$', 3)):with_move(function(opts) + return opts.char == '>' + end)) end, }, diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index ff5dfc1..12263c4 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -27,7 +27,6 @@ return { -- comment { 'numToStr/Comment.nvim', - version = false, dependencies = { 'JoosepAlviste/nvim-ts-context-commentstring', }, @@ -41,44 +40,14 @@ return { }) end, keys = { - { - 'gcc', - mode = 'n', - desc = 'Toggle comment line', - }, - { - 'gc', - mode = { 'n', 'o' }, - desc = 'Toggle comment linewise', - }, - { - 'gc', - mode = 'x', - desc = 'Toggle comment linewise (visual)', - }, - { - 'gbc', - mode = 'n', - desc = 'Toggle comment block', - }, - { - 'gb', - mode = { 'n', 'o' }, - desc = 'Toggle comment blockwise', - }, - { - 'gb', - mode = 'x', - desc = 'Toggle comment blockwise (visual)', - }, - { '/', "lua require('Comment.api').toggle.linewise.current()", desc = 'Toggle comment' }, - { - '/', - "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", - desc = 'Toggle comment', - mode = 'v', - }, + { 'gcc', mode = 'n', desc = 'Toggle comment line' }, + { 'gc', mode = { 'n', 'o' }, desc = 'Toggle comment linewise' }, + { 'gc', mode = 'x', desc = 'Toggle comment linewise (visual)' }, + { 'gbc', mode = 'n', desc = 'Toggle comment block' }, + { 'gb', mode = { 'n', 'o' }, desc = 'Toggle comment blockwise' }, + { 'gb', mode = 'x', desc = 'Toggle comment blockwise (visual)' }, }, + opts = {}, }, diff --git a/lua/plugins/format.lua b/lua/plugins/format.lua index 6f68e79..8c1d11b 100644 --- a/lua/plugins/format.lua +++ b/lua/plugins/format.lua @@ -27,6 +27,9 @@ return { }, formatters_by_ft = { ['lua'] = { 'stylua' }, + ['c'] = { 'clang_format' }, + ['cpp'] = { 'clang_format' }, + ['h'] = { 'clang_format' }, ['python'] = { 'ruff_fix', 'ruff_format', 'ruff_organize_imports' }, ['javascript'] = { 'biome' }, ['typescript'] = { 'biome' }, @@ -52,9 +55,10 @@ return { vim.b.conform_disable = not vim.b.conform_disable local status = vim.b.conform_disable and 'disabled' or 'enabled' vim.notify('Autoformat ' .. status, vim.log.levels.INFO) - end) + end, { desc = 'Toggle autoformat' }) require('mason-conform').setup({ ensure_installed = { + 'clang_format', 'ruff', 'stylua', 'prettier', diff --git a/lua/plugins/mini.lua b/lua/plugins/mini.lua index 6230846..259257d 100644 --- a/lua/plugins/mini.lua +++ b/lua/plugins/mini.lua @@ -19,18 +19,17 @@ return { -- surround action require('mini.surround').setup({ - n_lines = 25, mappings = { - add = 'ys', -- Add surrounding in Normal and Visual modes - delete = 'ds', -- Delete surrounding - find = '', -- Find surrounding (to the right) - find_left = '', -- Find surrounding (to the left) - highlight = '', -- Highlight surrounding - replace = 'cs', -- Replace surrounding - update_n_lines = '', -- Update `n_lines` + add = 'msa', + delete = 'msd', + find = 'msf', + find_left = 'msF', + highlight = 'msh', + replace = 'msr', + update_n_lines = 'msn', - suffix_last = 'l', -- Suffix to search with "prev" method - suffix_next = 'n', -- Suffix to search with "next" method + suffix_last = 'l', + suffix_next = 'n', }, }) diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index 0c86cbf..7811638 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -31,86 +31,12 @@ return { 'kevinhwang91/nvim-ufo', event = { 'BufReadPost', 'BufNewFile' }, dependencies = { 'kevinhwang91/promise-async', event = 'BufReadPost' }, - opts = { - provider_selector = function() - return { 'lsp', 'indent' } - end, - fold_virt_text_handler = function(virtText, lnum, endLnum, width, truncate) - local newVirtText = {} - local suffix = (' … %d '):format(endLnum - lnum) - local sufWidth = vim.fn.strdisplaywidth(suffix) - local targetWidth = width - sufWidth - local curWidth = 0 - for _, chunk in ipairs(virtText) do - local chunkText = chunk[1] - local chunkWidth = vim.fn.strdisplaywidth(chunkText) - if targetWidth > curWidth + chunkWidth then - table.insert(newVirtText, chunk) - else - chunkText = truncate(chunkText, targetWidth - curWidth) - local hlGroup = chunk[2] - table.insert(newVirtText, { chunkText, hlGroup }) - chunkWidth = vim.fn.strdisplaywidth(chunkText) - -- str width returned from truncate() may less than 2nd argument, need padding - if curWidth + chunkWidth < targetWidth then - suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth) - end - break - end - curWidth = curWidth + chunkWidth - end - table.insert(newVirtText, { suffix, 'MoreMsg' }) - return newVirtText - end, - open_fold_hl_timeout = 0, - }, - keys = { - { 'fd', 'zd', desc = 'Delete fold under cursor' }, - { 'fo', 'zo', desc = 'Open fold under cursor' }, - { 'fO', 'zO', desc = 'Open all folds under cursor' }, - { 'fc', 'zC', desc = 'Close all folds under cursor' }, - { 'fa', 'za', desc = 'Toggle fold under cursor' }, - { 'fA', 'zA', desc = 'Toggle all folds under cursor' }, - { 'fv', 'zv', desc = 'Show cursor line' }, - { - 'fM', - function() - require('ufo').closeAllFolds() + config = function() + require('ufo').setup({ + provider_selector = function(bufnr, filetype, buftype) + return { 'treesitter', 'indent' } end, - desc = 'Close all folds', - }, - { - 'fR', - function() - require('ufo').openAllFolds() - end, - desc = 'Open all folds', - }, - { - 'fm', - function() - require('ufo').closeFoldsWith() - end, - desc = 'Fold more', - }, - { - 'fr', - function() - require('ufo').openFoldsExceptKinds() - end, - desc = 'Fold less', - }, - { 'fx', 'zx', desc = 'Update folds' }, - { 'fz', 'zz', desc = 'Center this line' }, - { 'ft', 'zt', desc = 'Top this line' }, - { 'fb', 'zb', desc = 'Bottom this line' }, - { 'fg', 'zg', desc = 'Add word to spell list' }, - { 'fw', 'zw', desc = 'Mark word as bad/misspelling' }, - { 'fe', 'ze', desc = 'Right this line' }, - { 'fE', 'zE', desc = 'Delete all folds in current buffer' }, - { 'fs', 'zs', desc = 'Left this line' }, - { 'fH', 'zH', desc = 'Half screen to the left' }, - { 'fL', 'zL', desc = 'Half screen to the right' }, - }, + }) + end, }, } diff --git a/lua/plugins/util.lua b/lua/plugins/util.lua index 54e2fc4..0f9e012 100755 --- a/lua/plugins/util.lua +++ b/lua/plugins/util.lua @@ -83,7 +83,7 @@ return { shell = vim.o.shell, float_opts = { border = 'curved', -- 'single', 'double', 'shadow', etc. - winblend = 0, -- Set to 0 for full transparency + winblend = 0, -- Set to 0 for full transparency highlights = { border = 'Normal', background = 'Normal', @@ -114,16 +114,16 @@ return { picker_integration = true, keymaps = { prefix = 'u', -- Main prefix for uv commands - commands = true, -- Show uv commands menu (x) - run_file = true, -- Run current file (xr) + commands = true, -- Show uv commands menu (x) + run_file = true, -- Run current file (xr) run_selection = true, -- Run selected code (xs) - run_function = true, -- Run function (xf) - venv = true, -- Environment management (xe) - init = true, -- Initialize uv project (xi) - add = true, -- Add a package (xa) - remove = true, -- Remove a package (xd) - sync = true, -- Sync packages (xc) - sync_all = true, -- Sync all packages, extras and groups (xC) + run_function = true, -- Run function (xf) + venv = true, -- Environment management (xe) + init = true, -- Initialize uv project (xi) + add = true, -- Add a package (xa) + remove = true, -- Remove a package (xd) + sync = true, -- Sync packages (xc) + sync_all = true, -- Sync all packages, extras and groups (xC) }, }, },