refactor(plugins): improve plugin configurations and add C/C++ formatting

This commit is contained in:
sankalp committed 2025-10-16 22:46:07 +05:45
1 parent 1b7173fc43
commit f4d7cfbd13
6 files changed
+50 -147

No files matched your search

+13 -8
View File
@@ -2,18 +2,23 @@ return {
-- auto pairs -- auto pairs
{ {
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
enabled = false,
event = 'InsertEnter', event = 'InsertEnter',
config = function() config = function()
local npairs = require('nvim-autopairs') local npairs = require('nvim-autopairs')
local Rule = require('nvim-autopairs.rule')
local conds = require('nvim-autopairs.conds')
npairs.setup({ npairs.setup()
check_ts = true,
enable_check_bracket_line = true, -- Autoclosing angle-brackets.
fast_wrap = {}, npairs.add_rule(Rule('<', '>', {
map_cr = true, -- Avoid conflicts with nvim-ts-autotag.
map_bs = true, '-html',
}) '-javascriptreact',
'-typescriptreact',
}):with_pair(conds.before_regex('%a+:?:?$', 3)):with_move(function(opts)
return opts.char == '>'
end))
end, end,
}, },
+7 -38
View File
@@ -27,7 +27,6 @@ return {
-- comment -- comment
{ {
'numToStr/Comment.nvim', 'numToStr/Comment.nvim',
version = false,
dependencies = { dependencies = {
'JoosepAlviste/nvim-ts-context-commentstring', 'JoosepAlviste/nvim-ts-context-commentstring',
}, },
@@ -41,44 +40,14 @@ return {
}) })
end, end,
keys = { keys = {
{ { 'gcc', mode = 'n', desc = 'Toggle comment line' },
'gcc', { 'gc', mode = { 'n', 'o' }, desc = 'Toggle comment linewise' },
mode = 'n', { 'gc', mode = 'x', desc = 'Toggle comment linewise (visual)' },
desc = 'Toggle comment line', { 'gbc', mode = 'n', desc = 'Toggle comment block' },
}, { 'gb', mode = { 'n', 'o' }, desc = 'Toggle comment blockwise' },
{ { 'gb', mode = 'x', desc = 'Toggle comment blockwise (visual)' },
'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)',
},
{ '<leader>/', "<cmd>lua require('Comment.api').toggle.linewise.current()<cr>", desc = 'Toggle comment' },
{
'<leader>/',
"<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>",
desc = 'Toggle comment',
mode = 'v',
},
}, },
opts = {}, opts = {},
}, },
+5 -1
View File
@@ -27,6 +27,9 @@ return {
}, },
formatters_by_ft = { formatters_by_ft = {
['lua'] = { 'stylua' }, ['lua'] = { 'stylua' },
['c'] = { 'clang_format' },
['cpp'] = { 'clang_format' },
['h'] = { 'clang_format' },
['python'] = { 'ruff_fix', 'ruff_format', 'ruff_organize_imports' }, ['python'] = { 'ruff_fix', 'ruff_format', 'ruff_organize_imports' },
['javascript'] = { 'biome' }, ['javascript'] = { 'biome' },
['typescript'] = { 'biome' }, ['typescript'] = { 'biome' },
@@ -52,9 +55,10 @@ return {
vim.b.conform_disable = not vim.b.conform_disable vim.b.conform_disable = not vim.b.conform_disable
local status = vim.b.conform_disable and 'disabled' or 'enabled' local status = vim.b.conform_disable and 'disabled' or 'enabled'
vim.notify('Autoformat ' .. status, vim.log.levels.INFO) vim.notify('Autoformat ' .. status, vim.log.levels.INFO)
end) end, { desc = 'Toggle autoformat' })
require('mason-conform').setup({ require('mason-conform').setup({
ensure_installed = { ensure_installed = {
'clang_format',
'ruff', 'ruff',
'stylua', 'stylua',
'prettier', 'prettier',
+9 -10
View File
@@ -19,18 +19,17 @@ return {
-- surround action -- surround action
require('mini.surround').setup({ require('mini.surround').setup({
n_lines = 25,
mappings = { mappings = {
add = 'ys', -- Add surrounding in Normal and Visual modes add = 'msa',
delete = 'ds', -- Delete surrounding delete = 'msd',
find = '', -- Find surrounding (to the right) find = 'msf',
find_left = '', -- Find surrounding (to the left) find_left = 'msF',
highlight = '', -- Highlight surrounding highlight = 'msh',
replace = 'cs', -- Replace surrounding replace = 'msr',
update_n_lines = '', -- Update `n_lines` update_n_lines = 'msn',
suffix_last = 'l', -- Suffix to search with "prev" method suffix_last = 'l',
suffix_next = 'n', -- Suffix to search with "next" method suffix_next = 'n',
}, },
}) })
+6 -80
View File
@@ -31,86 +31,12 @@ return {
'kevinhwang91/nvim-ufo', 'kevinhwang91/nvim-ufo',
event = { 'BufReadPost', 'BufNewFile' }, event = { 'BufReadPost', 'BufNewFile' },
dependencies = { 'kevinhwang91/promise-async', event = 'BufReadPost' }, dependencies = { 'kevinhwang91/promise-async', event = 'BufReadPost' },
opts = { config = function()
provider_selector = function() require('ufo').setup({
return { 'lsp', 'indent' } provider_selector = function(bufnr, filetype, buftype)
end, return { 'treesitter', 'indent' }
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()
end, end,
desc = 'Close all folds', })
}, end,
{
'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' },
},
}, },
} }
+10 -10
View File
@@ -83,7 +83,7 @@ return {
shell = vim.o.shell, shell = vim.o.shell,
float_opts = { float_opts = {
border = 'curved', -- 'single', 'double', 'shadow', etc. border = 'curved', -- 'single', 'double', 'shadow', etc.
winblend = 0, -- Set to 0 for full transparency winblend = 0, -- Set to 0 for full transparency
highlights = { highlights = {
border = 'Normal', border = 'Normal',
background = 'Normal', background = 'Normal',
@@ -114,16 +114,16 @@ return {
picker_integration = true, picker_integration = true,
keymaps = { keymaps = {
prefix = '<leader>u', -- Main prefix for uv commands prefix = '<leader>u', -- Main prefix for uv commands
commands = true, -- Show uv commands menu (<leader>x) commands = true, -- Show uv commands menu (<leader>x)
run_file = true, -- Run current file (<leader>xr) run_file = true, -- Run current file (<leader>xr)
run_selection = true, -- Run selected code (<leader>xs) run_selection = true, -- Run selected code (<leader>xs)
run_function = true, -- Run function (<leader>xf) run_function = true, -- Run function (<leader>xf)
venv = true, -- Environment management (<leader>xe) venv = true, -- Environment management (<leader>xe)
init = true, -- Initialize uv project (<leader>xi) init = true, -- Initialize uv project (<leader>xi)
add = true, -- Add a package (<leader>xa) add = true, -- Add a package (<leader>xa)
remove = true, -- Remove a package (<leader>xd) remove = true, -- Remove a package (<leader>xd)
sync = true, -- Sync packages (<leader>xc) sync = true, -- Sync packages (<leader>xc)
sync_all = true, -- Sync all packages, extras and groups (<leader>xC) sync_all = true, -- Sync all packages, extras and groups (<leader>xC)
}, },
}, },
}, },