From 357dab6e1c6aac24bd68a26da8aa5b7a98e00033 Mon Sep 17 00:00:00 2001 From: "Paul B. Kim" Date: Fri, 6 Mar 2026 11:14:30 +0900 Subject: [PATCH] fix(plugins): initial plugin configuration fixes --- init.lua | 41 ++++++++++++------------- lua/custom/plugins/gitsigns.lua | 11 +++++-- lua/custom/plugins/persistence.lua | 48 ++++++++++++++++++++++++++++++ lua/custom/plugins/supermaven.lua | 3 +- lua/custom/wrapping.lua | 33 +++++++++++++++----- 5 files changed, 105 insertions(+), 31 deletions(-) create mode 100644 lua/custom/plugins/persistence.lua diff --git a/init.lua b/init.lua index d98e3d51..d74b4f56 100644 --- a/init.lua +++ b/init.lua @@ -179,6 +179,13 @@ vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set('n', '[d', function() + vim.diagnostic.jump { count = -1, float = true } +end, { desc = 'Go to previous [D]iagnostic' }) +vim.keymap.set('n', ']d', function() + vim.diagnostic.jump { count = 1, float = true } +end, { desc = 'Go to next [D]iagnostic' }) +vim.keymap.set('n', 'de', vim.diagnostic.open_float, { desc = 'Show [D]iagnostic [E]rror details' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -329,19 +336,6 @@ require('lazy').setup({ -- options to `gitsigns.nvim`. -- -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- -- This is often very useful to both group configuration, as well as handle @@ -402,8 +396,14 @@ require('lazy').setup({ -- Document existing key chains spec = { + { 'a', group = 'Harpoon [A]dd' }, + { 'd', group = '[D]iagnostics' }, + { 'g', group = '[G]it' }, + { 'm', group = '[M]arkdown' }, + { 'o', group = '[O]pencode' }, { 's', group = '[S]earch' }, { 't', group = '[T]oggle' }, + { 'w', group = '[W]indow' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, }, }, @@ -701,14 +701,15 @@ require('lazy').setup({ virtual_text = { source = 'if_many', spacing = 2, + severity = { min = vim.diagnostic.severity.WARN }, format = function(diagnostic) - local diagnostic_message = { - [vim.diagnostic.severity.ERROR] = diagnostic.message, - [vim.diagnostic.severity.WARN] = diagnostic.message, - [vim.diagnostic.severity.INFO] = diagnostic.message, - [vim.diagnostic.severity.HINT] = diagnostic.message, - } - return diagnostic_message[diagnostic.severity] + if diagnostic.severity == vim.diagnostic.severity.WARN then + return 'W: ' .. diagnostic.message + end + if diagnostic.severity == vim.diagnostic.severity.ERROR then + return 'E: ' .. diagnostic.message + end + return nil end, }, } diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua index cbbd22d2..cf3d4893 100644 --- a/lua/custom/plugins/gitsigns.lua +++ b/lua/custom/plugins/gitsigns.lua @@ -6,6 +6,13 @@ return { { 'lewis6991/gitsigns.nvim', opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, on_attach = function(bufnr) local gitsigns = require 'gitsigns' @@ -44,7 +51,7 @@ return { map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) - map('n', 'hu', gitsigns.stage_hunk, { desc = 'git [u]ndo stage hunk' }) + map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) map('n', 'hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) @@ -54,7 +61,7 @@ return { end, { desc = 'git [D]iff against last commit' }) -- Toggles map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) - map('n', 'tD', gitsigns.preview_hunk_inline, { desc = '[T]oggle git show [D]eleted' }) + map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) end, }, }, diff --git a/lua/custom/plugins/persistence.lua b/lua/custom/plugins/persistence.lua new file mode 100644 index 00000000..83fa606a --- /dev/null +++ b/lua/custom/plugins/persistence.lua @@ -0,0 +1,48 @@ +return { + 'folke/persistence.nvim', + event = 'BufReadPre', + opts = { + options = { 'buffers', 'curdir', 'tabpages', 'winsize', 'help', 'globals' }, + }, + keys = { + { + 'wr', + function() + require('persistence').load() + end, + desc = '[W]orkspace [R]estore session', + }, + { + 'wl', + function() + require('persistence').load { last = true } + end, + desc = '[W]orkspace [L]ast session', + }, + { + 'wd', + function() + require('persistence').stop() + end, + desc = '[W]orkspace [D]isable session save', + }, + }, + init = function() + vim.api.nvim_create_autocmd('VimEnter', { + group = vim.api.nvim_create_augroup('persistence-auto-restore', { clear = true }), + callback = function() + if vim.fn.argc(-1) > 0 then + return + end + + local ignored = { gitcommit = true, gitrebase = true } + if ignored[vim.bo.filetype] then + return + end + + require('persistence').load() + end, + nested = true, + }) + end, +} diff --git a/lua/custom/plugins/supermaven.lua b/lua/custom/plugins/supermaven.lua index b16e65ad..29be0696 100644 --- a/lua/custom/plugins/supermaven.lua +++ b/lua/custom/plugins/supermaven.lua @@ -1,5 +1,6 @@ return { 'supermaven-inc/supermaven-nvim', + event = 'InsertEnter', config = function() require('supermaven-nvim').setup { keymaps = { @@ -12,7 +13,7 @@ return { suggestion_color = '#ffffff', cterm = 244, }, - log_level = 'info', -- set to "off" to disable logging completely + log_level = 'off', disable_inline_completion = false, -- disables inline completion for use with cmp disable_keymaps = false, -- disables built in keymaps for more manual control condition = function() return false end, -- condition to check for stopping supermaven, `true` means to stop supermaven when the condition is true. diff --git a/lua/custom/wrapping.lua b/lua/custom/wrapping.lua index 3732a8c0..e7720140 100644 --- a/lua/custom/wrapping.lua +++ b/lua/custom/wrapping.lua @@ -3,6 +3,8 @@ local M = {} local defaults = { width = 100, patterns = { '*.md', '*.markdown' }, + max_lines = 5000, + max_bytes = 1024 * 1024, } local function apply_wrap_options(local_opts, width) @@ -16,12 +18,28 @@ local function apply_wrap_options(local_opts, width) local_opts.formatoptions:remove 'l' end -local function can_reflow(bufnr) - return vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].modifiable and vim.bo[bufnr].buftype == '' +local function can_reflow(bufnr, opts) + if not vim.api.nvim_buf_is_valid(bufnr) or not vim.bo[bufnr].modifiable or vim.bo[bufnr].buftype ~= '' then + return false + end + + if opts.max_lines and vim.api.nvim_buf_line_count(bufnr) > opts.max_lines then + return false + end + + local name = vim.api.nvim_buf_get_name(bufnr) + if name ~= '' and opts.max_bytes then + local stat = (vim.uv or vim.loop).fs_stat(name) + if stat and stat.size and stat.size > opts.max_bytes then + return false + end + end + + return true end -local function reflow_whole_buffer(bufnr, preserve_view) - if not can_reflow(bufnr) then +local function reflow_whole_buffer(bufnr, preserve_view, opts) + if not can_reflow(bufnr, opts) then return end @@ -37,12 +55,11 @@ end function M.setup(opts) opts = vim.tbl_deep_extend('force', defaults, opts or {}) - apply_wrap_options(vim.opt, opts.width) - local group = vim.api.nvim_create_augroup('custom_wrapping_rules', { clear = true }) vim.api.nvim_create_autocmd('FileType', { group = group, + pattern = 'markdown', callback = function() -- Apply after ftplugins so local overrides don't drop wrap options. vim.schedule(function() @@ -61,7 +78,7 @@ function M.setup(opts) end vim.b[args.buf].did_initial_wrap = true vim.schedule(function() - reflow_whole_buffer(args.buf, false) + reflow_whole_buffer(args.buf, false, opts) end) end, }) @@ -73,7 +90,7 @@ function M.setup(opts) if not vim.bo[args.buf].modified then return end - reflow_whole_buffer(args.buf, true) + reflow_whole_buffer(args.buf, true, opts) end, }) end