From 8feb221d41c8db8cad34e9bfc8a9981f099fe055 Mon Sep 17 00:00:00 2001 From: iofq Date: Tue, 6 May 2025 23:48:51 -0500 Subject: [PATCH] mini tweaks --- nvim/lua/config/init.lua | 2 + nvim/lua/plugins/mini.lua | 92 +++++++++++++++------------------ nvim/lua/plugins/misc.lua | 11 +++- nvim/lua/plugins/treesitter.lua | 5 +- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/nvim/lua/config/init.lua b/nvim/lua/config/init.lua index ccfec4d..04214a9 100644 --- a/nvim/lua/config/init.lua +++ b/nvim/lua/config/init.lua @@ -60,6 +60,8 @@ vim.keymap.set('n', '', vim.cmd.bnext, { noremap = true, silent = true }) vim.keymap.set('n', '', vim.cmd.bprev, { noremap = true, silent = true }) vim.keymap.set('v', '<', '', '>gv') +vim.keymap.set({ 'n', 'v' }, '[[', '{') +vim.keymap.set({ 'n', 'v' }, ']]', '}') -- resize splits if window got resized vim.api.nvim_create_autocmd({ 'VimResized' }, { diff --git a/nvim/lua/plugins/mini.lua b/nvim/lua/plugins/mini.lua index 3b9e282..6a7557e 100644 --- a/nvim/lua/plugins/mini.lua +++ b/nvim/lua/plugins/mini.lua @@ -1,3 +1,42 @@ +-- ripped from lazyvim +local function setup_pairs(opts) + local pairs = require('mini.pairs') + pairs.setup(opts) + local open = pairs.open + pairs.open = function(pair, neigh_pattern) + if vim.fn.getcmdline() ~= '' then + return open(pair, neigh_pattern) + end + local o, c = pair:sub(1, 1), pair:sub(2, 2) + local line = vim.api.nvim_get_current_line() + local cursor = vim.api.nvim_win_get_cursor(0) + local next = line:sub(cursor[2] + 1, cursor[2] + 1) + local before = line:sub(1, cursor[2]) + if opts.markdown and o == '`' and vim.bo.filetype == 'markdown' and before:match('^%s*``') then + return '`\n```' .. vim.api.nvim_replace_termcodes('', true, true, true) + end + if opts.skip_next and next ~= '' and next:match(opts.skip_next) then + return o + end + if opts.skip_ts and #opts.skip_ts > 0 then + local ok, captures = pcall(vim.treesitter.get_captures_at_pos, 0, cursor[1] - 1, math.max(cursor[2] - 1, 0)) + for _, capture in ipairs(ok and captures or {}) do + if vim.tbl_contains(opts.skip_ts, capture.capture) then + return o + end + end + end + if opts.skip_unbalanced and next == c and c ~= o then + local _, count_open = line:gsub(vim.pesc(pair:sub(1, 1)), '') + local _, count_close = line:gsub(vim.pesc(pair:sub(2, 2)), '') + if count_close > count_open then + return o + end + end + return open(pair, neigh_pattern) + end +end + return { { 'echasnovski/mini.nvim', @@ -12,34 +51,6 @@ return { noremap = true, desc = 'git diff overlay', }, - { - 'gr', - function() - return MiniDiff.operator('reset') .. 'gh' - end, - noremap = true, - desc = 'git diff reset', - }, - { - 'gd', - function() - return MiniGit.show_at_cursor() - end, - noremap = true, - desc = 'git show at cursor', - }, - { - 'gb', - 'vert Git blame -- %', - noremap = true, - desc = 'git blame', - }, - { - 'gg', - ':Git ', - noremap = true, - desc = 'git command', - }, }, config = function() require('mini.basics').setup { mappings = { windows = true } } @@ -85,29 +96,13 @@ return { prefix = 'gR', }, } - require('mini.pairs').setup { + setup_pairs { modes = { insert = true, command = true, terminal = false }, skip_next = [=[[%w%%%'%[%"%.%`%$]]=], skip_ts = { 'string' }, skip_unbalanced = true, markdown = true, } - require('mini.git').setup() - local align_blame = function(au_data) - if au_data.data.git_subcommand ~= 'blame' then - return - end - - -- Align blame output with source - local win_src = au_data.data.win_source - vim.wo.wrap = false - vim.fn.winrestview { topline = vim.fn.line('w0', win_src) } - vim.api.nvim_win_set_cursor(0, { vim.fn.line('.', win_src), 0 }) - - -- Bind both windows so that they scroll together - vim.wo[win_src].scrollbind, vim.wo.scrollbind = true, true - end - vim.api.nvim_create_autocmd('User', { pattern = 'MiniGitCommandSplit', callback = align_blame }) require('mini.surround').setup() require('mini.splitjoin').setup { detect = { separator = '[,;\n]' } } @@ -160,15 +155,14 @@ return { show_integration_count = false, }, } - vim.keymap.set('n', 'nm', map.toggle, { noremap = true, desc = 'minimap open' }) local multi = require('mini.keymap').map_multistep local combo = require('mini.keymap').map_combo - combo({ 'i', 'c', 'x', 's' }, 'wq', 'l') - multi({ 'i', 's' }, '', { 'blink_accept', 'vimsnippet_next', 'jump_after_close', 'jump_after_tsnode' }) - multi({ 'i', 's' }, '', { 'vimsnippet_prev', 'jump_before_open', 'jump_before_tsnode' }) + combo({ 'v', 'r', 'i', 's' }, 'wq', 'l') + multi({ 'i', 's' }, '', { 'blink_accept', 'vimsnippet_next' }) + multi({ 'i', 's' }, '', { 'vimsnippet_prev' }) end) end, }, diff --git a/nvim/lua/plugins/misc.lua b/nvim/lua/plugins/misc.lua index a27f40d..3f1c82d 100644 --- a/nvim/lua/plugins/misc.lua +++ b/nvim/lua/plugins/misc.lua @@ -37,7 +37,7 @@ return { 'MeanderingProgrammer/render-markdown.nvim', event = 'VeryLazy', opts = { - ft = { 'markdown', 'codecompanion ' }, + ft = { 'markdown', 'codecompanion' }, }, }, { @@ -68,6 +68,13 @@ return { }, keys = { { 'nb', vim.cmd.DiffviewOpen, noremap = true, desc = 'diffview open' }, + { + 'nh', + vim.cmd.DiffviewFileHistory, + mode = { 'n', 'v' }, + noremap = true, + desc = 'diffview history', + }, }, }, { @@ -100,6 +107,8 @@ return { 'mini', 'treesitter', 'neogit', + 'native_lsp', + 'diagnostic', }, }, }, diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 37a48cd..acdcada 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -48,6 +48,7 @@ return { ['ia'] = '@parameter.inner', ['ik'] = '@assignment.lhs', ['iv'] = '@assignment.rhs', + ['is'] = { query = '@local.scope', query_group = 'locals', desc = 'Select language scope' }, }, }, move = { @@ -55,12 +56,12 @@ return { goto_next_start = { [']a'] = '@parameter.inner', [']f'] = '@function.outer', - [']]'] = '@block.outer', + ['}'] = '@statement.outer', }, goto_previous_start = { ['[a'] = '@parameter.inner', ['[f'] = '@function.outer', - ['[['] = '@block.outer', + ['{'] = '@statement.outer', }, }, swap = {