### Install mini.nvim Library with lazy.nvim Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md Install the 'mini.nvim' library using lazy.nvim. Set version to false for the main branch or '*' for the stable branch. ```lua { 'nvim-mini/mini.nvim', version = false }, ``` ```lua { 'nvim-mini/mini.nvim', version = '*' }, ``` -------------------------------- ### Install mini.nvim Library with vim-plug Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md Install the 'mini.nvim' library using vim-plug. Use the default branch for the main version or specify the 'stable' branch. ```vim Plug 'nvim-mini/mini.nvim' ``` ```vim Plug 'nvim-mini/mini.nvim', { 'branch': 'stable' } ``` -------------------------------- ### Setup Mini Diff with Default Configuration Source: https://context7.com/nvim-mini/mini.diff/llms.txt Initializes the mini.diff module with default settings. This is the most basic setup and must be called to enable plugin functionality. ```lua require('mini.diff').setup() ``` -------------------------------- ### MiniDiff.setup() Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Module setup function for Mini.diff. Allows configuration of various aspects of the plugin. ```APIDOC ## MiniDiff.setup() `MiniDiff.setup`({config}) ### Description Module setup ### Parameters - **config** (table|nil) - Module config table. See |MiniDiff.config|. ### Usage ```lua require('mini.diff').setup() -- use default config -- OR require('mini.diff').setup({}) -- replace {} with your config table ``` ``` -------------------------------- ### Install mini.diff Standalone with lazy.nvim Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md Install the mini.diff plugin as a standalone repository using lazy.nvim. Set version to false for the main branch or '*' for the stable branch. ```lua { 'nvim-mini/mini.diff', version = false }, ``` ```lua { 'nvim-nvim/mini.diff', version = '*' }, ``` -------------------------------- ### Install mini.diff Standalone with mini.deps Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md Use these snippets to install the mini.diff plugin as a standalone repository with mini.deps. Specify the 'stable' branch for the release version. ```lua add('nvim-mini/mini.diff') ``` ```lua add({ source = 'nvim-mini/mini.diff', checkout = 'stable' }) ``` -------------------------------- ### Install mini.diff Standalone with vim-plug Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md Install the mini.diff plugin as a standalone repository using vim-plug. Use the default branch for the main version or specify the 'stable' branch. ```vim Plug 'nvim-mini/mini.diff' ``` ```vim Plug 'nvim-mini/mini.diff', { 'branch': 'stable' } ``` -------------------------------- ### Setup MiniDiff with Custom Configuration Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Initializes the mini.diff plugin with a custom configuration table. This allows for fine-tuning of various plugin options. ```lua require('mini.diff').setup({}) ``` -------------------------------- ### Setup Mini Diff Source: https://context7.com/nvim-mini/mini.diff/llms.txt Initializes the mini-diff module with optional configuration. Must be called to enable the plugin functionality. Creates the global `MiniDiff` table for scripting access. ```APIDOC ## Setup Mini Diff ### Description Initializes the mini-diff module with optional configuration. Must be called to enable the plugin functionality. Creates the global `MiniDiff` table for scripting access. ### Method `require('mini.diff').setup(options) ### Parameters #### Options Table - **view** (table) - Optional - Configuration for the diff view style, signs, and priority. - **style** (string) - Optional - 'sign' or 'sign_and_line'. - **signs** (table) - Optional - Custom signs for add, change, delete. - **priority** (number) - Optional - Priority for virtual text. - **source** (table | nil) - Optional - Configuration for the diff source. `nil` uses Git by default. - **delay** (table) - Optional - Delay in milliseconds for text change updates. - **text_change** (number) - Optional - Delay for text change updates. - **mappings** (table) - Optional - Key mappings for diff operations. - **apply** (string) - Optional - Mapping for applying hunks. - **reset** (string) - Optional - Mapping for resetting hunks. - **textobject** (string) - Optional - Mapping for text object selection. - **goto_first** (string) - Optional - Mapping to go to the first hunk. - **goto_prev** (string) - Optional - Mapping to go to the previous hunk. - **goto_next** (string) - Optional - Mapping to go to the next hunk. - **goto_last** (string) - Optional - Mapping to go to the last hunk. - **options** (table) - Optional - Diff algorithm options. - **algorithm** (string) - Optional - 'histogram', 'diff', etc. - **indent_heuristic** (boolean) - Optional - Enable indent heuristic. - **linematch** (number) - Optional - Line match percentage. - **wrap_goto** (boolean) - Optional - Wrap around when going to next/previous hunk. ### Request Example ```lua -- Basic setup with default configuration require('mini.diff').setup() -- Custom setup with modified options require('mini.diff').setup({ view = { style = 'sign', signs = { add = '+', change = '~', delete = '-' }, priority = 199, }, source = nil, -- Uses Git by default delay = { text_change = 200, }, mappings = { apply = 'gh', reset = 'gH', textobject = 'gh', goto_first = '[H', goto_prev = '[h', goto_next = ']h', goto_last = ']H', }, options = { algorithm = 'histogram', indent_heuristic = true, linematch = 60, wrap_goto = false, }, }) ``` ``` -------------------------------- ### Setup Mini Diff with Custom Options Source: https://context7.com/nvim-mini/mini.diff/llms.txt Initializes the mini.diff module with custom configuration options. This allows for fine-tuning the diff view style, signs, source, delay, mappings, and diff algorithm. ```lua require('mini.diff').setup({ view = { style = 'sign', signs = { add = '+', change = '~', delete = '-' }, priority = 199, }, source = nil, -- Uses Git by default delay = { text_change = 200, }, mappings = { apply = 'gh', reset = 'gH', textobject = 'gh', goto_first = '[H', goto_prev = '[h', goto_next = ']h', goto_last = ']H', }, options = { algorithm = 'histogram', indent_heuristic = true, linematch = 60, wrap_goto = false, }, }) ``` -------------------------------- ### Export hunks to quickfix list Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Use MiniDiff.export() to get hunks from all enabled buffers and set them to the quickfix list. ```lua vim.fn.setqflist(MiniDiff.export('qf')) ``` -------------------------------- ### Define Git Source for MiniDiff Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Example of defining a Git source for MiniDiff, which watches the Git index and computes reference text. This is the default source. ```lua MiniDiff.gen_source.git() ``` -------------------------------- ### Configure Multiple Sources Source: https://context7.com/nvim-mini/mini.diff/llms.txt Configure `mini.diff` to attempt multiple sources in order. If the first source fails to attach, the next one is tried. This example tries Git first, falling back to the save source. ```lua -- Try Git first, fall back to save source require('mini.diff').setup({ source = { MiniDiff.gen_source.git(), MiniDiff.gen_source.save(), }, }) -- For non-Git files, will automatically use save source ``` -------------------------------- ### Configure MiniDiff View Style and Signs Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Sets up the mini.diff plugin with a custom view configuration. This example specifically changes the visualization style to 'sign' and defines custom characters for added, changed, and deleted hunks. ```lua require('mini.diff').setup({ view = { style = 'sign', signs = { add = '+', change = '~', delete = '-' }, }, }) ``` -------------------------------- ### Format MiniDiff Summary String Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt This example shows how to override the default `minidiff_summary_string` by creating an autocommand that listens for the `MiniDiffUpdated` event. It formats the summary based on the `minidiff_summary` buffer-local variable. ```lua local format_summary = function(data) local summary = vim.b[data.buf].minidiff_summary local t = {} if summary.add > 0 then table.insert(t, '+' .. summary.add) end if summary.change > 0 then table.insert(t, '~' .. summary.change) end if summary.delete > 0 then table.insert(t, '-' .. summary.delete) end vim.b[data.buf].minidiff_summary_string = table.concat(t, ' ') end local au_opts = { pattern = 'MiniDiffUpdated', callback = format_summary } vim.api.nvim_create_autocmd('User', au_opts) ``` -------------------------------- ### Enable diff processing in a buffer Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Call MiniDiff.enable() to start diff processing in a specified buffer. Defaults to the current buffer. ```lua MiniDiff.enable() ``` -------------------------------- ### MiniDiff.enable() Source: https://context7.com/nvim-mini/mini.diff/llms.txt Enables diff processing for a specific buffer. This attaches the configured source and starts tracking changes between the buffer text and reference text. Automatically called when entering valid file buffers. ```APIDOC ## MiniDiff.enable() ### Description Enables diff processing for a specific buffer. This attaches the configured source and starts tracking changes between the buffer text and reference text. Automatically called when entering valid file buffers. ### Method `MiniDiff.enable(buffer_id) ### Parameters #### Path Parameters - **buffer_id** (number) - Required - The ID of the buffer to enable diff processing for. Use `0` for the current buffer. ### Request Example ```lua -- Enable diff for current buffer MiniDiff.enable(0) -- Enable diff for a specific buffer by ID local buf_id = vim.api.nvim_get_current_buf() MiniDiff.enable(buf_id) ``` ``` -------------------------------- ### Go to Hunk Range Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Navigate to the first, previous, next, or last hunk range in the current buffer. Supports specifying the number of times to advance and a starting line. ```lua MiniDiff.goto_hunk({direction}, {opts}) ``` -------------------------------- ### Enable Diff for Current Buffer Source: https://context7.com/nvim-mini/mini.diff/llms.txt Enables diff processing for the current buffer (buffer ID 0). This attaches the configured source and starts tracking changes. ```lua MiniDiff.enable(0) ``` -------------------------------- ### Get buffer diff data Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Retrieve the diff data for a specific buffer using MiniDiff.get_buf_data(). Defaults to the current buffer. ```lua MiniDiff.get_buf_data() ``` -------------------------------- ### Perform Action Over Region with Operator Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Perform an action (apply, reset, yank) over a region defined by marks. Used in mappings. Example shows mapping to yank reference lines of hunk range under cursor. ```lua local rhs = function() return MiniDiff.operator('yank') .. 'gh' end vim.keymap.set('n', 'ghy', rhs, { expr = true, remap = true }) ``` -------------------------------- ### Get Diff Data for Current Buffer Source: https://context7.com/nvim-mini/mini.diff/llms.txt Retrieves all diff-related data for the current buffer (buffer ID 0) if diff processing is enabled. This includes configuration, hunks, overlay state, and summary statistics. ```lua local data = MiniDiff.get_buf_data(0) if data then print('Source: ' .. data.summary.source_name) print('Hunk ranges: ' .. data.summary.n_ranges) print('Added lines: ' .. data.summary.add) print('Changed lines: ' .. data.summary.change) print('Deleted lines: ' .. data.summary.delete) print('Overlay enabled: ' .. tostring(data.overlay)) -- Iterate through hunks for i, hunk in ipairs(data.hunks) do print(string.format('Hunk %d: type=%s, buf_start=%d, buf_count=%d', i, hunk.type, hunk.buf_start, hunk.buf_count)) end end ``` -------------------------------- ### Configure Git Source Source: https://context7.com/nvim-mini/mini.diff/llms.txt Configure `mini.diff` to use Git index as the reference. This is the default source and applies hunks by staging them to the Git index. Requires Git version 2.38.0 or higher. ```lua -- Explicit Git source configuration require('mini.diff').setup({ source = MiniDiff.gen_source.git(), }) -- Git source requires Git version 2.38.0 or higher -- Hunks applied with 'gh' are staged to Git index -- Unstaging is not supported - use full Git client ``` -------------------------------- ### Configure MiniDiff with Different Sources Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Set up mini.diff with a single source like 'save' or multiple sources like 'git' and 'save'. Ensure Git version is at least 2.38.0 for git source. ```lua local diff = require('mini.diff') -- Single `save` source diff.setup({ source = diff.gen_source.save() }) -- Multiple sources (attempted to attach in order) diff.setup({ source = { diff.gen_source.git(), diff.gen_source.save() } }) ``` -------------------------------- ### Multiple Sources Configuration Source: https://context7.com/nvim-mini/mini.diff/llms.txt Configure multiple sources that are attempted in order. If the first source fails to attach, the next one is tried. ```APIDOC ## Multiple Sources Configuration ### Description Configure multiple sources that are attempted in order. If the first source fails to attach, the next one is tried. ### Method Lua Function Call (within `require('mini.diff').setup()`) ### Parameters None directly, but the `source` option accepts a table of source configurations. ### Request Example ```lua -- Try Git first, fall back to save source require('mini.diff').setup({ source = { MiniDiff.gen_source.git(), MiniDiff.gen_source.save(), }, }) -- For non-Git files, will automatically use save source ``` ### Response None (configures the plugin behavior) ``` -------------------------------- ### Default Configuration for mini.diff Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md This is the default configuration for mini.diff. It covers visualization styles, sign characters, extmark priority, source options, asynchronous delays, module mappings, and general diff algorithm options. Ensure `require('mini.diff').setup()` is called to enable functionality. ```lua -- No need to copy this inside `setup()`. Will be used automatically. { -- Options for how hunks are visualized view = { -- Visualization style. Possible values are 'sign' and 'number'. -- Default: 'number' if line numbers are enabled, 'sign' otherwise. style = vim.go.number and 'number' or 'sign', -- Signs used for hunks with 'sign' view signs = { add = '▒', change = '▒', delete = '▒' }, -- Priority of used visualization extmarks priority = 199, }, -- Source(s) for how reference text is computed/updated/etc -- Uses content from Git index by default source = nil, -- Delays (in ms) defining asynchronous processes delay = { -- How much to wait before update following every text change text_change = 200, }, -- Module mappings. Use `''` (empty string) to disable one. mappings = { -- Apply hunks inside a visual/operator region apply = 'gh', -- Reset hunks inside a visual/operator region reset = 'gH', -- Hunk range textobject to be used inside operator -- Works also in Visual mode if mapping differs from apply and reset textobject = 'gh', -- Go to hunk range in corresponding direction goto_first = '[H', goto_prev = '[h', goto_next = ']h', goto_last = ']H', }, -- Various options options = { -- Diff algorithm. See `:h vim.diff()`. algorithm = 'histogram', -- Whether to use "indent heuristic". See `:h vim.diff()`. indent_heuristic = true, -- The amount of second-stage diff to align lines linematch = 60, -- Whether to wrap around edges during hunk navigation wrap_goto = false, }, } ``` -------------------------------- ### MiniDiff None Source Configuration Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Allows buffers to be enabled without setting any reference text. Use this if relying on manual |MiniDiff.set_ref_text()| calls. ```lua diff.gen_source.none() ``` -------------------------------- ### MiniDiff Git Source Configuration Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Uses file text from Git index as reference. Requires Git version at least 2.38.0. There is no capability for unstaging hunks. ```lua diff.gen_source.git() ``` -------------------------------- ### Configure None Source Source: https://context7.com/nvim-mini/mini.diff/llms.txt Configure `mini.diff` with a 'do nothing' source, enabling buffers without setting reference text. This is useful when relying on manual `MiniDiff.set_ref_text()` calls. ```lua -- Use none source for manual reference text control require('mini.diff').setup({ source = MiniDiff.gen_source.none(), }) -- Then manually set reference text as needed MiniDiff.set_ref_text(0, 'your reference text here') ``` -------------------------------- ### Export Hunks to Quickfix/Location Lists Source: https://context7.com/nvim-mini/mini.diff/llms.txt Use `export` to export hunks to 'qf' format for quickfix or location lists. Supports exporting from all enabled buffers or just the current one. ```lua -- Export all hunks to quickfix list vim.fn.setqflist(MiniDiff.export('qf')) vim.cmd('copen') -- Export hunks from current buffer only vim.fn.setqflist(MiniDiff.export('qf', { scope = 'current' })) -- Export to location list for current window vim.fn.setloclist(0, MiniDiff.export('qf', { scope = 'current' })) vim.cmd('lopen') ``` -------------------------------- ### MiniDiff.export() - Export Hunks Source: https://context7.com/nvim-mini/mini.diff/llms.txt Exports hunks to a specified format. Currently supports 'qf' format for quickfix/location lists. Can export from all enabled buffers or just the current one. ```APIDOC ## MiniDiff.export() ### Description Exports hunks to a specified format. Currently supports 'qf' format for quickfix/location lists. Can export from all enabled buffers or just the current one. ### Method Lua Function Call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **format** (string) - Required - Format to export ('qf'). - **options** (table) - Optional - Configuration options. - **scope** (string) - Optional - Scope of export ('all' or 'current', default: 'all'). ### Request Example ```lua -- Export all hunks to quickfix list vim.fn.setqflist(MiniDiff.export('qf')) vim.cmd('copen') -- Export hunks from current buffer only vim.fn.setqflist(MiniDiff.export('qf', { scope = 'current' })) -- Export to location list for current window vim.fn.setloclist(0, MiniDiff.export('qf', { scope = 'current' })) vim.cmd('lopen') ``` ### Response - **data** (table) - Description of exported hunks in the specified format. ``` -------------------------------- ### MiniDiff Save Source Configuration Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Uses text at the latest save as the reference. This results in diff showing the difference after the latest save. ```lua diff.gen_source.save() ``` -------------------------------- ### MiniDiff.goto_hunk() - Hunk Navigation Source: https://context7.com/nvim-mini/mini.diff/llms.txt Navigates to a hunk range in the current buffer. Supports directions: first, prev, next, last. Optionally wraps around buffer edges and supports count multiplier. ```APIDOC ## MiniDiff.goto_hunk() ### Description Navigates to a hunk range in the current buffer. Supports directions: first, prev, next, last. Optionally wraps around buffer edges and supports count multiplier. ### Method Lua Function Call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **direction** (string) - Required - Direction to navigate ('first', 'prev', 'next', 'last'). - **options** (table) - Optional - Configuration options. - **n_times** (number) - Optional - Number of times to move (default: 1). - **wrap** (boolean) - Optional - Whether to wrap around buffer edges (default: false). ### Request Example ```lua -- Go to next hunk MiniDiff.goto_hunk('next') -- Go to previous hunk MiniDiff.goto_hunk('prev') -- Go to first hunk in buffer MiniDiff.goto_hunk('first') -- Go to last hunk in buffer MiniDiff.goto_hunk('last') -- Go to next hunk with wrapping and count MiniDiff.goto_hunk('next', { n_times = 3, wrap = true }) -- Custom mapping with count support vim.keymap.set('n', ']h', function() MiniDiff.goto_hunk('next', { n_times = vim.v.count1 }) end, { desc = 'Go to next hunk' }) ``` ### Response None (modifies cursor position) ``` -------------------------------- ### Buffer-Local Variables Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Provides information on buffer-local variables `vim.b.minidiff_summary` and `vim.b.minidiff_summary_string` which offer an overview of hunks in the current buffer. ```APIDOC ## Buffer-Local Variables Each enabled buffer has the following buffer-local variables which can be used in custom statusline to show an overview of hunks in current buffer: - `vim.b.minidiff_summary` is a table with the following fields: - `source_name` - name of the active source. This is the only present field if buffer's reference text is not (yet) set. - `n_ranges` - number of hunk ranges (sequences of contiguous hunks). - `add` - number of added lines. - `change` - number of changed lines. - `delete` - number of deleted lines. - `vim.b.minidiff_summary_string` is a string representation of summary with a fixed format. Empty string if there is no reference text (yet). It is expected to be used as is. To achieve different formatting, use `vim.b.minidiff_summary` to construct one. The best way to do this is by overriding `vim.b.minidiff_summary_string` inside |MiniDiff-update-event|: ```lua local format_summary = function(data) local summary = vim.b[data.buf].minidiff_summary local t = {} if summary.add > 0 then table.insert(t, '+' .. summary.add) end if summary.change > 0 then table.insert(t, '~' .. summary.change) end if summary.delete > 0 then table.insert(t, '-' .. summary.delete) end vim.b[data.buf].minidiff_summary_string = table.concat(t, ' ') end local au_opts = { pattern = 'MiniDiffUpdated', callback = format_summary } vim.api.nvim_create_autocmd('User', au_opts) ``` ``` -------------------------------- ### Configure Save Source Source: https://context7.com/nvim-mini/mini.diff/llms.txt Configure `mini.diff` to use the buffer content at the last save as the reference. This is useful for tracking unsaved changes without Git. ```lua -- Use save source to show changes since last save require('mini.diff').setup({ source = MiniDiff.gen_source.save(), }) -- Useful for tracking unsaved changes without Git ``` -------------------------------- ### Compare Buffer Against File on Disk Source: https://context7.com/nvim-mini/mini.diff/llms.txt Compares the current buffer's content against the content of the file it represents on disk. This is achieved by reading the file and setting its content as the reference text. ```lua local path = vim.api.nvim_buf_get_name(0) local file = io.open(path, 'r') if file then local content = file:read('*all') file:close() MiniDiff.set_ref_text(0, content) end ``` -------------------------------- ### MiniDiff.gen_source.git() - Git Source Configuration Source: https://context7.com/nvim-mini/mini.diff/llms.txt Generates a Git source that uses the file content from Git index as reference. This is the default source. Applying hunks stages them to the Git index. ```APIDOC ## MiniDiff.gen_source.git() ### Description Generates a Git source that uses the file content from Git index as reference. This is the default source. Applying hunks stages them to the Git index. ### Method Lua Function Call ### Parameters None ### Request Example ```lua -- Explicit Git source configuration require('mini.diff').setup({ source = MiniDiff.gen_source.git(), }) -- Git source requires Git version 2.38.0 or higher -- Hunks applied with 'gh' are staged to Git index -- Unstaging is not supported - use full Git client ``` ### Response A source configuration object for Git. ``` -------------------------------- ### MiniDiff.get_buf_data() Source: https://context7.com/nvim-mini/mini.diff/llms.txt Returns a table containing all diff-related data for an enabled buffer, including configuration, hunks array, overlay state, reference text, and summary statistics. Returns nil if the buffer is not enabled. ```APIDOC ## MiniDiff.get_buf_data() ### Description Returns a table containing all diff-related data for an enabled buffer, including configuration, hunks array, overlay state, reference text, and summary statistics. Returns nil if the buffer is not enabled. ### Method `MiniDiff.get_buf_data(buffer_id) ### Parameters #### Path Parameters - **buffer_id** (number) - Required - The ID of the buffer to retrieve data from. Use `0` for the current buffer. ### Response #### Success Response (200) - **configuration** (table) - The current configuration for the buffer. - **hunks** (table) - An array of diff hunks. - **type** (string) - Type of hunk ('add', 'change', 'delete'). - **buf_start** (number) - Starting line in the buffer. - **buf_count** (number) - Number of lines in the buffer. - **ref_start** (number) - Starting line in the reference text. - **ref_count** (number) - Number of lines in the reference text. - **overlay** (boolean) - Whether the overlay view is enabled. - **ref_text** (string | table) - The reference text used for diffing. - **summary** (table) - Summary statistics of the diff. - **source_name** (string) - Name of the diff source. - **n_ranges** (number) - Number of diff ranges. - **add** (number) - Number of added lines. - **change** (number) - Number of changed lines. - **delete** (number) - Number of deleted lines. ### Request Example ```lua -- Get diff data for current buffer local data = MiniDiff.get_buf_data(0) if data then print('Source: ' .. data.summary.source_name) print('Hunk ranges: ' .. data.summary.n_ranges) print('Added lines: ' .. data.summary.add) print('Changed lines: ' .. data.summary.change) print('Deleted lines: ' .. data.summary.delete) print('Overlay enabled: ' .. tostring(data.overlay)) -- Iterate through hunks for i, hunk in ipairs(data.hunks) do print(string.format('Hunk %d: type=%s, buf_start=%d, buf_count=%d', i, hunk.type, hunk.buf_start, hunk.buf_count)) end end ``` ``` -------------------------------- ### Navigate Between Hunks Source: https://context7.com/nvim-mini/mini.diff/llms.txt Use `goto_hunk` to navigate to the first, previous, next, or last hunk. Supports count multipliers and wrapping around buffer edges. ```lua -- Go to next hunk MiniDiff.goto_hunk('next') -- Go to previous hunk MiniDiff.goto_hunk('prev') -- Go to first hunk in buffer MiniDiff.goto_hunk('first') -- Go to last hunk in buffer MiniDiff.goto_hunk('last') -- Go to next hunk with wrapping and count MiniDiff.goto_hunk('next', { n_times = 3, wrap = true }) -- Custom mapping with count support vim.keymap.set('n', ']h', function() MiniDiff.goto_hunk('next', { n_times = vim.v.count1 }) end, { desc = 'Go to next hunk' }) ``` -------------------------------- ### MiniDiff.gen_source.none() - None Source Configuration Source: https://context7.com/nvim-mini/mini.diff/llms.txt Generates a "do nothing" source that enables buffers without setting reference text. Useful when relying on manual `MiniDiff.set_ref_text()` calls. ```APIDOC ## MiniDiff.gen_source.none() ### Description Generates a "do nothing" source that enables buffers without setting reference text. Useful when relying on manual `MiniDiff.set_ref_text()` calls. ### Method Lua Function Call ### Parameters None ### Request Example ```lua -- Use none source for manual reference text control require('mini.diff').setup({ source = MiniDiff.gen_source.none(), }) -- Then manually set reference text as needed MiniDiff.set_ref_text(0, 'your reference text here') ``` ### Response A source configuration object for no source. ``` -------------------------------- ### MiniDiff.config Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Default configuration table for Mini.diff, detailing options for view, source, delays, mappings, and other settings. ```APIDOC ## MiniDiff.config `MiniDiff.config` ### Defaults ```lua MiniDiff.config = { -- Options for how hunks are visualized view = { -- Visualization style. Possible values are 'sign' and 'number'. -- Default: 'number' if line numbers are enabled, 'sign' otherwise. style = vim.go.number and 'number' or 'sign', -- Signs used for hunks with 'sign' view signs = { add = '▒', change = '▒', delete = '▒' }, -- Priority of used visualization extmarks priority = 199, }, -- Source(s) for how reference text is computed/updated/etc -- Uses content from Git index by default source = nil, -- Delays (in ms) defining asynchronous processes delay = { -- How much to wait before update following every text change text_change = 200, }, -- Module mappings. Use `''` (empty string) to disable one. mappings = { -- Apply hunks inside a visual/operator region apply = 'gh', -- Reset hunks inside a visual/operator region reset = 'gH', -- Hunk range textobject to be used inside operator -- Works also in Visual mode if mapping differs from apply and reset textobject = 'gh', -- Go to hunk range in corresponding direction goto_first = '[H', goto_prev = '[h', goto_next = ']h', goto_last = ']H', }, -- Various options options = { -- Diff algorithm. See `:h vim.diff()`. algorithm = 'histogram', -- Whether to use "indent heuristic". See `:h vim.diff()`. indent_heuristic = true, -- The amount of second-stage diff to align lines linematch = 60, -- Whether to wrap around edges during hunk navigation wrap_goto = false, }, } ``` ### View Options `config.view` contains settings for how diff hunks are visualized. Example of using custom signs: ```lua require('mini.diff').setup({ view = { style = 'sign', signs = { add = '+', change = '~', delete = '-' }, }, }) ``` `view.style` is a string defining visualization style. Can be one of "sign" (as a colored sign in a |sign-column|) or "number" (colored line number). Default: "number" if |'number'| option is enabled, "sign" otherwise. Note: with "sign" style it is better to have |'signcolumn'| always shown. `view.signs` is a table with one or two character strings used as signs for corresponding ("add", "change", "delete") hunks. Default: all hunks use "▒" character resulting in a contiguous colored lines. `view.priority` is a number with priority used for visualization and overlay |extmarks|. Default: 199 which is one less than `user` in |vim.hl.priorities| (on Neovim<0.11 see |vim.hl.priorities|) to have higher priority than automated extmarks but not as in user enabled ones. ``` -------------------------------- ### MiniDiff Configuration Options Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Customization options available for the Mini.diff plugin. ```APIDOC ## Configuration Options `config.options` contains various customization options. ### `options.algorithm` - **Type**: string - **Description**: Defines which diff algorithm to use. Default: "histogram". See |vim.diff()| for possible values. ### `options.indent_heuristic` - **Type**: boolean - **Description**: Defines whether to use indent heuristic for more naturally aligned hunks. Default: `true`. ### `options.linematch` - **Type**: number - **Description**: Defines hunk size for which a second stage diff is executed for better aligned and more granular hunks. Default: 60. See |vim.diff()| and 'diffopt' for more details. ### `options.wrap_goto` - **Type**: boolean - **Description**: Indicates whether to wrap around edges during hunk navigation. Default: `false`. ``` -------------------------------- ### Navigation and Operators Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Functions for navigating between diff hunks and performing actions over selected regions. ```APIDOC ## MiniDiff.goto_hunk({direction}, {opts}) ### Description Go to hunk range in current buffer. ### Parameters - **direction** `(string)`: One of "first", "prev", "next", "last". - **opts** `(table|nil)`: Options. A table with fields: - **n_times** `(number)`: Number of times to advance. Default: |v:count1|. - **line_start** `(number)`: Line number to start from for directions "prev" and "next". Default: cursor line. - **wrap** `(boolean)`: Whether to wrap around edges. Default: `options.wrap` value of the config. ``` ```APIDOC ## MiniDiff.operator({mode}) ### Description Perform action over region defined by marks. Used in mappings. Example of a mapping to yank reference lines of hunk range under cursor (assuming default 'config.mappings.textobject'): ```lua local rhs = function() return MiniDiff.operator('yank') .. 'gh' end vim.keymap.set('n', 'ghy', rhs, { expr = true, remap = true }) ``` ### Parameters - **mode** `(string)`: One of "apply", "reset", "yank", or the ones used in |g@|. ``` ```APIDOC ## MiniDiff.textobject() ### Description Select hunk range textobject. Selects all contiguous lines adjacent to cursor line which are in any (not ``` -------------------------------- ### MiniDiff.gen_source.save() - Save Source Configuration Source: https://context7.com/nvim-mini/mini.diff/llms.txt Generates a source that uses the buffer content at the last save as reference. Shows differences since the last write operation. ```APIDOC ## MiniDiff.gen_source.save() ### Description Generates a source that uses the buffer content at the last save as reference. Shows differences since the last write operation. ### Method Lua Function Call ### Parameters None ### Request Example ```lua -- Use save source to show changes since last save require('mini.diff').setup({ source = MiniDiff.gen_source.save(), }) -- Useful for tracking unsaved changes without Git ``` ### Response A source configuration object for save state. ``` -------------------------------- ### Formatting Diff Summary on Update Source: https://context7.com/nvim-mini/mini.diff/llms.txt Set up an autocommand to format the diff summary string whenever the `MiniDiffUpdated` event is triggered. This callback function updates the `minidiff_summary_string` buffer-local variable. ```lua -- Custom format via MiniDiffUpdated event local format_summary = function(data) local summary = vim.b[data.buf].minidiff_summary if not summary then return end local t = {} if summary.add > 0 then table.insert(t, '+' .. summary.add) end if summary.change > 0 then table.insert(t, '~' .. summary.change) end if summary.delete > 0 then table.insert(t, '-' .. summary.delete) end vim.b[data.buf].minidiff_summary_string = table.concat(t, ' ') end vim.api.nvim_create_autocmd('User', { pattern = 'MiniDiffUpdated', callback = format_summary, }) ``` -------------------------------- ### Map to Toggle Diff Overlay Source: https://context7.com/nvim-mini/mini.diff/llms.txt Sets a key mapping to quickly toggle the diff overlay view for the current buffer. This allows for easy access to detailed diff information. ```lua vim.keymap.set('n', 'do', function() MiniDiff.toggle_overlay(0) end, { desc = 'Toggle diff overlay' }) ``` -------------------------------- ### MiniDiff.gen_source Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Generates builtin sources for Mini.diff. ```APIDOC ## `MiniDiff.gen_source` ### Description Generate builtin sources. ### Method `MiniDiff.gen_source` ``` -------------------------------- ### Map to Toggle Diff Source: https://context7.com/nvim-mini/mini.diff/llms.txt Sets a key mapping to quickly toggle diff processing for the current buffer. This provides a convenient way to enable or disable diff visualization on demand. ```lua vim.keymap.set('n', 'td', function() MiniDiff.toggle(0) end, { desc = 'Toggle diff' }) ``` -------------------------------- ### MiniDiff.toggle_overlay() Source: https://context7.com/nvim-mini/mini.diff/llms.txt Toggles the overlay view which shows detailed diff information directly in the text area. Displays deleted lines as virtual text, highlights added lines, and shows word-level diffs for changed lines with equal line counts. ```APIDOC ## MiniDiff.toggle_overlay() ### Description Toggles the overlay view which shows detailed diff information directly in the text area. Displays deleted lines as virtual text, highlights added lines, and shows word-level diffs for changed lines with equal line counts. ### Method `MiniDiff.toggle_overlay(buffer_id) ### Parameters #### Path Parameters - **buffer_id** (number) - Required - The ID of the buffer to toggle the overlay view for. Use `0` for the current buffer. ### Request Example ```lua -- Toggle overlay for current buffer MiniDiff.toggle_overlay(0) -- Map to a key for quick overlay toggle vim.keymap.set('n', 'do', function() MiniDiff.toggle_overlay(0) end, { desc = 'Toggle diff overlay' }) ``` ``` -------------------------------- ### Accessing Diff Summary Information Source: https://context7.com/nvim-mini/mini.diff/llms.txt Use buffer-local variables to access diff summary data for statusline integration. The `minidiff_summary` variable provides a table, while `minidiff_summary_string` offers a pre-formatted string. ```lua -- Access summary table local summary = vim.b.minidiff_summary -- summary = { source_name = 'git', n_ranges = 3, add = 5, change = 2, delete = 1 } -- Access pre-formatted string local summary_str = vim.b.minidiff_summary_string -- summary_str = '#3 +5 ~2 -1' ``` -------------------------------- ### MiniDiff.do_hunks() - Hunk Actions Source: https://context7.com/nvim-mini/mini.diff/llms.txt Performs actions on hunks within a specified line range. Supports apply (stage in Git), reset (revert to reference), and yank (copy reference lines to register) actions. ```APIDOC ## MiniDiff.do_hunks() ### Description Performs actions on hunks within a specified line range. Supports apply (stage in Git), reset (revert to reference), and yank (copy reference lines to register) actions. ### Method Lua Function Call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **buffer** (number) - Required - Buffer handle. - **action** (string) - Required - Action to perform ('apply', 'reset', 'yank'). - **options** (table) - Optional - Configuration options. - **line_start** (number) - Required - Starting line of the range. - **line_end** (number) - Required - Ending line of the range. - **register** (string) - Optional - Register to use for 'yank' action. ### Request Example ```lua -- Apply hunks in lines 10-20 of current buffer MiniDiff.do_hunks(0, 'apply', { line_start = 10, line_end = 20 }) -- Reset hunks in lines 5-15 MiniDiff.do_hunks(0, 'reset', { line_start = 5, line_end = 15 }) -- Yank reference lines of hunks in range to register "a" MiniDiff.do_hunks(0, 'yank', { line_start = 1, line_end = 50, register = 'a' }) -- Apply all hunks in the buffer local line_count = vim.api.nvim_buf_line_count(0) MiniDiff.do_hunks(0, 'apply', { line_start = 1, line_end = line_count }) ``` ### Response None (modifies buffer state or registers) ``` -------------------------------- ### Toggle diff processing in a buffer Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Use MiniDiff.toggle() to switch the diff processing state for a buffer. Defaults to the current buffer. ```lua MiniDiff.toggle() ``` -------------------------------- ### Create Autocmd for MiniDiffUpdated Event Source: https://github.com/nvim-mini/mini.diff/blob/main/README.md This Lua code sets up an autocommand to trigger a custom function whenever the MiniDiffUpdated event occurs. The function formats the diff summary data and updates the buffer-local variable `minidiff_summary_string`. ```lua local format_summary = function(data) local summary = vim.b[data.buf].minidiff_summary local t = {} if summary.add > 0 then table.insert(t, '+' .. summary.add) end if summary.change > 0 then table.insert(t, '~' .. summary.change) end if summary.delete > 0 then table.insert(t, '-' .. summary.delete) end vim.b[data.buf].minidiff_summary_string = table.concat(t, ' ') end local au_opts = { pattern = 'MiniDiffUpdated', callback = format_summary } vim.api.nvim_create_autocmd('User', au_opts) ``` -------------------------------- ### Toggle overlay view in a buffer Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Call MiniDiff.toggle_overlay() to show or hide the overlay view for diffs in a buffer. Defaults to the current buffer. ```lua MiniDiff.toggle_overlay() ``` -------------------------------- ### Set reference text for a buffer Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Use MiniDiff.set_ref_text() to set the reference text for diffing. This will also enable diff processing if it's not already active. Defaults to the current buffer. ```lua MiniDiff.set_ref_text(bufnr, text) ``` ```lua MiniDiff.set_ref_text(bufnr, {}) ``` -------------------------------- ### MiniDiff API Endpoints Source: https://github.com/nvim-mini/mini.diff/blob/main/doc/mini-diff.txt Functions for enabling, disabling, and managing diffs in Neovim buffers. ```APIDOC ## `MiniDiff.enable` ### Description Enable diff processing in buffer. ### Method `MiniDiff.enable({buf_id})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. ``` ```APIDOC ## `MiniDiff.disable` ### Description Disable diff processing in buffer. ### Method `MiniDiff.disable({buf_id})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. ``` ```APIDOC ## `MiniDiff.toggle` ### Description Toggle diff processing in buffer. Enable if disabled, disable if enabled. ### Method `MiniDiff.toggle({buf_id})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. ``` ```APIDOC ## `MiniDiff.toggle_overlay` ### Description Toggle overlay view in buffer. ### Method `MiniDiff.toggle_overlay({buf_id})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. ``` ```APIDOC ## `MiniDiff.export` ### Description Export hunks from current or all enabled buffers. ### Method `MiniDiff.export({format}, {opts})` ### Parameters - **format** (string) - Required - Output format. Currently only `'qf'` value is supported. - **opts** (table|nil) - Optional - Options. Possible fields: - **scope** (string) - Scope defining from which buffers to use hunks. One of "all" or "current". ### Return - **(table)** - Result of export. Depends on the `format`. If "qf", an array compatible with |setqflist()| and |setloclist()|. ### Request Example ```lua -- Set quickfix list from all available hunks vim.fn.setqflist(MiniDiff.export('qf', { scope = 'all' })) ``` ``` ```APIDOC ## `MiniDiff.get_buf_data` ### Description Get diff data for a specific buffer. ### Method `MiniDiff.get_buf_data({buf_id})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. ### Return - **(table|nil)** - Table with buffer diff data or `nil` if buffer is not enabled. Table has the following fields: - **config** (table) - Config used for this particular buffer. - **hunks** (table) - Array of hunks. See |MiniDiff-hunk-specification|. - **overlay** (boolean) - Whether an overlay view is shown. - **ref_text** (string|nil) - Current value of reference text. Lines are separated with newline character (`'\n'`). Can be `nil` indicating that reference text was not yet set. - **summary** (table) - Overall diff summary. See |MiniDiff-diff-summary|. ``` ```APIDOC ## `MiniDiff.set_ref_text` ### Description Set reference text for the buffer. This will call |MiniDiff.enable()| for the target buffer if it is not already enabled. ### Method `MiniDiff.set_ref_text({buf_id}, {text})` ### Parameters - **buf_id** (number) - Optional - Target buffer identifier. Default: 0 for current buffer. - **text** (string|table) - New reference text. Either a string with `\n` to separate lines or an array of lines. Use an empty table to unset current reference text. Default: `{}`. A newline character is appended at the end if it's not already present. ```