### Polyfill for vim.system() using jobstart for Neovim Lua (v0.10-) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua function provides a compatibility layer for Neovim versions older than v0.10, replacing `vim.system()`. It uses `vim.fn.jobstart` and `vim.fn.jobwait` to execute external commands, capturing their exit code, standard output, and standard error. This allows the `vim.ui.input()` example to function on older Neovim installations. ```Lua --- @class system.Results --- @field code integer --- @field stdout string --- @field stderr string --- @param cmd string|string[] --- @return system.Results local function system(cmd) local results = {} local function callback(_, data, event) if event == "exit" then results.code = data elseif event == "stdout" or event == "stderr" then results[event] = table.concat(data, "\n") end end vim.fn.jobwait({ vim.fn.jobstart(cmd, { on_exit = callback, on_stdout = callback, on_stderr = callback, stdout_buffered = true, stderr_buffered = true }) }) return results end ``` -------------------------------- ### Installing Diffview.nvim Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md Instructions for installing the Diffview.nvim plugin using popular Neovim package managers like Vim-Plug and Packer.nvim. ```vim Plug 'sindrets/diffview.nvim' ``` ```lua use "sindrets/diffview.nvim" ``` -------------------------------- ### Running Diffview.nvim from a Specific Directory (Shell) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This command opens Diffview.nvim as if Git was started in the specified directory (`/foo/bar/baz`). This is useful for viewing diffs relative to a different working tree. ```Shell DiffviewOpen -C/foo/bar/baz ``` -------------------------------- ### Checking Out GitHub PR Locally (Console) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This command uses the GitHub CLI (`gh`) to check out a pull request locally by its ID. It's a prerequisite for reviewing a PR using `diffview.nvim`. ```console $ gh pr checkout {PR_ID} ``` -------------------------------- ### Configuring Default DiffviewOpen Arguments (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua configuration snippet sets `--imply-local` as a default argument for `DiffviewOpen` in `diffview.nvim`. This ensures that LSP features are always available when opening diffs, enhancing the review experience. ```lua default_args = { DiffviewOpen = { "--imply-local" } } ``` -------------------------------- ### Creating Keymap for Git Commit with vim.ui.input() in Neovim Lua (v0.10+) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua snippet defines a keymap (`cc`) that uses `vim.ui.input()` to prompt the user for a commit message. After receiving the message, it executes `git commit -m` using `vim.system()`. It includes error handling to notify the user if the commit fails or succeeds, displaying relevant output from Git. ```Lua keymaps = { file_panel = { { "n", "cc", function() vim.ui.input({ prompt = "Commit message: " }, function(msg) if not msg then return end local results = vim.system({ "git", "commit", "-m", msg }, { text = true }):wait() if results.code ~= 0 then vim.notify( "Commit failed with the message: \n" .. vim.trim(results.stdout .. "\n" .. results.stderr), vim.log.levels.ERROR, { title = "Commit" } ) else vim.notify(results.stdout, vim.log.levels.INFO, { title = "Commit" }) end end) end } } } ``` -------------------------------- ### Opening Symmetric Diff for PR Review (Vimscript) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Vim command opens `diffview.nvim` to show a symmetric difference between the current branch (PR branch) and its merge-base in `origin/HEAD`. The `--imply-local` flag ensures that the working tree versions of files are shown, enabling LSP features for review. ```vimscript :DiffviewOpen origin/HEAD...HEAD --imply-local ``` -------------------------------- ### Configuring Fugitive Commit Keymaps (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua snippet defines keymaps for `vim-fugitive` within `diffview.nvim`'s file panel. It provides shortcuts for committing staged changes (`cc`), amending the last commit (`ca`), and populating the command line with `:Git commit ` (`c`), streamlining the commit workflow. ```lua keymaps = { file_panel = { { "n", "cc", "Git commit wincmd J", { desc = "Commit staged changes" } }, { "n", "ca", "Git commit --amend wincmd J", { desc = "Amend the last commit" } }, { "n", "c", ":Git commit ", { desc = "Populate command line with \":Git commit \"" } } } } ``` -------------------------------- ### Detecting Default Remote Branch (Shell) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This shell command configures Git to automatically query the remote (`origin`) and detect its default branch. This resolves the `fatal: Not a valid object name origin/HEAD` error when the local origin remote lacks a default branch configuration. ```sh git remote set-head -a origin ``` -------------------------------- ### Using DiffviewFileHistory Command in Neovim Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md These examples demonstrate various ways to invoke the `DiffviewFileHistory` command in Neovim. The command opens a file history view, listing commits affecting specified paths or the current buffer's range. It supports pathspecs, directory paths, and Git range options. ```Neovim Command :DiffviewFileHistory ``` ```Neovim Command :DiffviewFileHistory % ``` ```Neovim Command :DiffviewFileHistory path/to/some/file.txt ``` ```Neovim Command :DiffviewFileHistory path/to/some/directory ``` ```Neovim Command :DiffviewFileHistory include/this and/this :!but/not/this ``` ```Neovim Command :DiffviewFileHistory --range=origin..HEAD ``` ```Neovim Command :DiffviewFileHistory --range=feat/example-branch ``` ```Neovim Command :'<,'>DiffviewFileHistory ``` -------------------------------- ### Creating Keymaps for Git Commits with neovim-remote in Neovim Lua Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua snippet defines keymaps for committing staged changes (`cc`) and amending the last commit (`ca`) from a file panel. These mappings use `jobstart` to execute Git commands, which are then handled by `neovim-remote` to open the commit message in a new Neovim split. An autocommand `BufWinEnter` is used to adjust the window layout after the commit buffer opens. ```Lua keymaps = { file_panel = { { "n", "cc", "[[call jobstart(["git", "commit"]) | au BufWinEnter * ++once wincmd J]]", { desc = "Commit staged changes" } }, { "n", "ca", "[[call jobstart(["git", "commit", "--amend"]) | au BufWinEnter * ++once wincmd J]]", { desc = "Amend the last commit" } } } } ``` -------------------------------- ### Executing Git Commit with :!cmd in Neovim Vimscript Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Vimscript command demonstrates a simple way to commit changes using Neovim's `:!cmd` feature. It directly executes a shell command to perform a Git commit with a hardcoded message. This method is suitable for quick, non-interactive commits. ```Vimscript :!git commit -m 'some commit message' ``` -------------------------------- ### Listing All Git Stashes (Vimscript) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Vim command uses `DiffviewFileHistory` with the `--walk-reflogs` (`-g`) option and `--range=stash` to list all stashes in the file history panel. It traverses the reflog for the `refs/stash` reference to display all saved stashes. ```vimscript :DiffviewFileHistory -g --range=stash ``` -------------------------------- ### Creating Keymaps for Git Commits with :terminal in Neovim Lua Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua snippet defines keymaps for committing staged changes (`cc`) and amending the last commit (`ca`) using Neovim's `:terminal` command. When triggered, these mappings open a new split window and execute the Git commit command within an interactive terminal, which results in a nested Neovim instance. ```Lua keymaps = { file_panel = { { "n", "cc", "sp wincmd J term git commit", { desc = "Commit staged changes" } }, { "n", "ca", "sp wincmd J term git commit -amend", { desc = "Amend the last commit" } } } } ``` -------------------------------- ### Reviewing Individual PR Commits (Vimscript) Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Vim command uses `DiffviewFileHistory` to review changes from individual commits within a PR. It employs a symmetric difference range, `--right-only` to limit commits to the PR branch, and `--no-merges` to filter out merge commits, providing a clean list of non-merge PR commits. ```vimscript :DiffviewFileHistory --range=origin/HEAD...HEAD --right-only --no-merges ``` -------------------------------- ### Configuring GIT_EDITOR with neovim-remote in Neovim Lua Source: https://github.com/sindrets/diffview.nvim/blob/main/USAGE.md This Lua snippet configures the `GIT_EDITOR`, `EDITOR`, and `VISUAL` environment variables to use `neovim-remote` (`nvr`). It checks if `nvr` is executable and sets up the variables to open Git editor sessions in a new split within the current Neovim instance, preventing nested Neovim processes. The `--remote-wait` flag ensures Neovim waits for the editor session to close. ```Lua if vim.fn.executable("nvr") == 1 then local nvr = "nvr --servername " .. vim.v.servername .. " " vim.env.GIT_EDITOR = nvr .. "-cc split +'setl bh=delete' --remote-wait" vim.env.EDITOR = nvr .. "-l --remote" -- (Optional) vim.env.VISUAL = nvr .. "-l --remote" -- (Optional) end ``` -------------------------------- ### Opening Diffview with Git Revisions and Paths Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md Demonstrates how to open a Diffview session to compare against the current index, specific Git revisions, ranges, or branches, and how to narrow down the view to specific file paths. ```vim :DiffviewOpen :DiffviewOpen HEAD~2 :DiffviewOpen HEAD~4..HEAD~2 :DiffviewOpen d4a7b0d :DiffviewOpen d4a7b0d^! :DiffviewOpen d4a7b0d..519b30e :DiffviewOpen origin/main...HEAD :DiffviewOpen HEAD~2 -- lua/diffview plugin ``` -------------------------------- ### Configuring diffview.nvim with Default Options (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet demonstrates the default configuration for the diffview.nvim plugin in Lua. It covers a wide range of settings including binary diffs, enhanced highlighting, Git/Hg commands, icon usage, help hints, index watching, custom icons and signs, various view layouts (default, merge_tool, file_history), file panel styles (list/tree), file history log options, commit log panel settings, default arguments for commands, and keymap definitions for navigation and actions within diff views. ```Lua -- Lua local actions = require("diffview.actions") require("diffview").setup({ diff_binaries = false, -- Show diffs for binaries enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl| git_cmd = { "git" }, -- The git executable followed by default args. hg_cmd = { "hg" }, -- The hg executable followed by default args. use_icons = true, -- Requires nvim-web-devicons show_help_hints = true, -- Show hints for how to open the help panel watch_index = true, -- Update views and index buffers when the git index changes. icons = { -- Only applies when use_icons is true. folder_closed = "", folder_open = "", }, signs = { fold_closed = "", fold_open = "", done = "✓", }, view = { -- Configure the layout and behavior of different types of views. -- Available layouts: -- 'diff1_plain' -- |'diff2_horizontal' -- |'diff2_vertical' -- |'diff3_horizontal' -- |'diff3_vertical' -- |'diff3_mixed' -- |'diff4_mixed' -- For more info, see |diffview-config-view.x.layout|. default = { -- Config for changed files, and staged files in diff views. layout = "diff2_horizontal", disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view. winbar_info = false, -- See |diffview-config-view.x.winbar_info| }, merge_tool = { -- Config for conflicted files in diff views during a merge or rebase. layout = "diff3_horizontal", disable_diagnostics = true, -- Temporarily disable diagnostics for diff buffers while in the view. winbar_info = true, -- See |diffview-config-view.x.winbar_info| }, file_history = { -- Config for changed files in file history views. layout = "diff2_horizontal", disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view. winbar_info = false, -- See |diffview-config-view.x.winbar_info| }, }, file_panel = { listing_style = "tree", -- One of 'list' or 'tree' tree_options = { -- Only applies when listing_style is 'tree' flatten_dirs = true, -- Flatten dirs that only contain one single dir folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'. }, win_config = { -- See |diffview-config-win_config| position = "left", width = 35, win_opts = {}, }, }, file_history_panel = { log_options = { -- See |diffview-config-log_options| git = { single_file = { diff_merges = "combined", }, multi_file = { diff_merges = "first-parent", }, }, hg = { single_file = {}, multi_file = {}, }, }, win_config = { -- See |diffview-config-win_config| position = "bottom", height = 16, win_opts = {}, }, }, commit_log_panel = { win_config = {}, -- See |diffview-config-win_config| }, default_args = { -- Default args prepended to the arg-list for the listed commands DiffviewOpen = {}, DiffviewFileHistory = {}, }, hooks = {}, -- See |diffview-config-hooks| keymaps = { disable_defaults = false, -- Disable the default keymaps view = { -- The `view` bindings are active in the diff buffers, only when the current -- tabpage is a Diffview. { "n", "", actions.select_next_entry, { desc = "Open the diff for the next file" } }, { "n", "", actions.select_prev_entry, { desc = "Open the diff for the previous file" } }, { "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } }, { "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } }, { "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } }, { "n", "", actions.goto_file_split, { desc = "Open the file in a new split" } }, { "n", "gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } }, { "n", "e", actions.focus_files, { desc = "Bring focus to the file panel" } }, { "n", "b", actions.toggle_files, { desc = "Toggle the file panel." } }, { "n", "g", actions.cycle_layout, { desc = "Cycle through available layouts." } }, { "n", "[x", actions.prev_conflict, { desc = "In the merge-tool: jump to the previous conflict" } } } } }) ``` -------------------------------- ### Configuring Help Panel Keymaps in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet specifies normal mode keymaps for the help panel in Diffview.nvim. These simple mappings provide ways to close the help menu using 'q' or the escape key. ```Lua help_panel = { { "n", "q", actions.close, { desc = "Close help menu" } }, { "n", "", actions.close, { desc = "Close help menu" } } } ``` -------------------------------- ### Configuring Single Window Diff Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This Lua mapping defines a keybinding for single-window diff layouts in Diffview.nvim. It provides a shortcut to open the help panel, offering guidance on available commands and features specific to this view. ```Lua diff1 = { -- Mappings in single window diff layouts { "n", "g?", actions.help({ "view", "diff1" }), { desc = "Open the help panel" } } } ``` -------------------------------- ### Basic Keymap Definition with Vim Command and Lua Function (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet illustrates the basic syntax for defining keymaps in Diffview.nvim. It shows how to map a key to either a Vim command string (e.g., `:echom 'foo'`) or directly to a Lua function, both executed in normal mode. ```Lua view = { -- Vim command: ["a"] = "echom 'foo'", -- Lua function: ["b"] = function() print("bar") end } ``` -------------------------------- ### Configuring File Panel Keymaps in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet defines a comprehensive set of normal mode keymaps for the file panel in Diffview.nvim. These mappings enable users to navigate entries, open diffs, scroll the view, and manage files across different Neovim windows and tabs. ```Lua { "n", "l", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "", actions.scroll_view(-0.25), { desc = "Scroll the view up" } }, { "n", "", actions.scroll_view(0.25), { desc = "Scroll the view down" } }, { "n", "", actions.select_next_entry, { desc = "Open the diff for the next file" } }, { "n", "", actions.select_prev_entry, { desc = "Open the diff for the previous file" } }, { "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } }, { "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } }, { "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } }, { "n", "", actions.goto_file_split, { desc = "Open the file in a new split" } }, { "n", "gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } }, { "n", "e", actions.focus_files, { desc = "Bring focus to the file panel" } }, { "n", "b", actions.toggle_files, { desc = "Toggle the file panel" } }, { "n", "g", actions.cycle_layout, { desc = "Cycle available layouts" } }, { "n", "g?", actions.help("file_history_panel"), { desc = "Open the help panel" } } ``` -------------------------------- ### Configuring File Panel Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md These Lua mappings define comprehensive keybindings for the file panel in Diffview.nvim. They enable navigation through file entries, opening diffs, staging/unstaging changes, restoring files, opening commit logs, and managing folds within the panel. ```Lua file_panel = { { "n", "j", actions.next_entry, { desc = "Bring the cursor to the next file entry" } }, { "n", "", actions.next_entry, { desc = "Bring the cursor to the next file entry" } }, { "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } }, { "n", "", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } }, { "n", "", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "l", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "-", actions.toggle_stage_entry, { desc = "Stage / unstage the selected entry" } }, { "n", "s", actions.toggle_stage_entry, { desc = "Stage / unstage the selected entry" } }, { "n", "S", actions.stage_all, { desc = "Stage all entries" } }, { "n", "U", actions.unstage_all, { desc = "Unstage all entries" } }, { "n", "X", actions.restore_entry, { desc = "Restore entry to the state on the left side" } }, { "n", "L", actions.open_commit_log, { desc = "Open the commit log panel" } }, { "n", "zo", actions.open_fold, { desc = "Expand fold" } }, { "n", "h", actions.close_fold, { desc = "Collapse fold" } }, { "n", "zc", actions.close_fold, { desc = "Collapse fold" } }, { "n", "za", actions.toggle_fold, { desc = "Toggle fold" } }, { "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } } } ``` -------------------------------- ### Configuring Option Panel Keymaps in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet defines normal mode keymaps specifically for the option panel in Diffview.nvim. It allows users to select options, close the panel, and access the help documentation relevant to the option panel. ```Lua option_panel = { { "n", "", actions.select_entry, { desc = "Change the current option" } }, { "n", "q", actions.close, { desc = "Close the panel" } }, { "n", "g?", actions.help("option_panel"), { desc = "Open the help panel" } } } ``` -------------------------------- ### Configuring Two-Way Diff Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This Lua mapping defines a keybinding for two-way diff layouts in Diffview.nvim. It provides a shortcut to open the help panel, offering guidance on available commands and features specific to this view. ```Lua diff2 = { -- Mappings in 2-way diff layouts { "n", "g?", actions.help({ "view", "diff2" }), { desc = "Open the help panel" } } } ``` -------------------------------- ### Managing Diffview Sessions and Panels Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md Convenience commands for closing the current Diffview, toggling the file panel visibility, focusing on the file panel, and refreshing the file list. ```vim :DiffviewClose :DiffviewToggleFiles :DiffviewFocusFiles :DiffviewRefresh ``` -------------------------------- ### Diffing Index Against a Git Revision with Diffview.nvim (Shell) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This command opens Diffview.nvim to show the difference between the Git index and a specific revision (e.g., `HEAD~2`). If no revision is given, it defaults to `HEAD`. ```Shell DiffviewOpen HEAD~2 --cached ``` -------------------------------- ### Opening Diffview File History Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md Commands to open the file history view, allowing users to list and review commits affecting specific paths or the current file. ```vim :DiffviewFileHistory :DiffviewFileHistory % ``` -------------------------------- ### Configuring File Panel Keybindings in Neovim Diffview (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet defines a set of normal mode keybindings for the `diffview.nvim` file panel. These bindings allow users to navigate files, manage folds, refresh views, toggle panels, and resolve merge conflicts directly from the file list. ```Lua { "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } }, { "n", "", actions.scroll_view(-0.25), { desc = "Scroll the view up" } }, { "n", "", actions.scroll_view(0.25), { desc = "Scroll the view down" } }, { "n", "", actions.select_next_entry, { desc = "Open the diff for the next file" } }, { "n", "", actions.select_prev_entry, { desc = "Open the diff for the previous file" } }, { "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } }, { "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } }, { "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } }, { "n", "", actions.goto_file_split, { desc = "Open the file in a new split" } }, { "n", "gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } }, { "n", "i", actions.listing_style, { desc = "Toggle between 'list' and 'tree' views" } }, { "n", "f", actions.toggle_flatten_dirs, { desc = "Flatten empty subdirectories in tree listing style" } }, { "n", "R", actions.refresh_files, { desc = "Update stats and entries in the file list" } }, { "n", "e", actions.focus_files, { desc = "Bring focus to the file panel" } }, { "n", "b", actions.toggle_files, { desc = "Toggle the file panel" } }, { "n", "g", actions.cycle_layout, { desc = "Cycle available layouts" } }, { "n", "[x", actions.prev_conflict, { desc = "Go to the previous conflict" } }, { "n", "]x", actions.next_conflict, { desc = "Go to the next conflict" } }, { "n", "g?", actions.help("file_panel"), { desc = "Open the help panel" } }, { "n", "cO", actions.conflict_choose_all("ours"), { desc = "Choose the OURS version of a conflict for the whole file" } }, { "n", "cT", actions.conflict_choose_all("theirs"), { desc = "Choose the THEIRS version of a conflict for the whole file" } }, { "n", "cB", actions.conflict_choose_all("base"), { desc = "Choose the BASE version of a conflict for the whole file" } }, { "n", "cA", actions.conflict_choose_all("all"), { desc = "Choose all the versions of a conflict for the whole file" } }, { "n", "dX", actions.conflict_choose_all("none"), { desc = "Delete the conflict region for the whole file" } } ``` -------------------------------- ### Configuring Merge Tool Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md These Lua mappings define keyboard shortcuts for resolving merge conflicts within the Diffview.nvim merge tool. They allow users to navigate conflicts, choose specific versions (ours, theirs, base, all), or delete conflict regions, both for individual conflicts and across the entire file. ```Lua { "n", "]x", actions.next_conflict, { desc = "In the merge-tool: jump to the next conflict" } }, { "n", "co", actions.conflict_choose("ours"), { desc = "Choose the OURS version of a conflict" } }, { "n", "ct", actions.conflict_choose("theirs"), { desc = "Choose the THEIRS version of a conflict" } }, { "n", "cb", actions.conflict_choose("base"), { desc = "Choose the BASE version of a conflict" } }, { "n", "ca", actions.conflict_choose("all"), { desc = "Choose all the versions of a conflict" } }, { "n", "dx", actions.conflict_choose("none"), { desc = "Delete the conflict region" } }, { "n", "cO", actions.conflict_choose_all("ours"), { desc = "Choose the OURS version of a conflict for the whole file" } }, { "n", "cT", actions.conflict_choose_all("theirs"), { desc = "Choose the THEIRS version of a conflict for the whole file" } }, { "n", "cB", actions.conflict_choose_all("base"), { desc = "Choose the BASE version of a conflict for the whole file" } }, { "n", "cA", actions.conflict_choose_all("all"), { desc = "Choose all the versions of a conflict for the whole file" } }, { "n", "dX", actions.conflict_choose_all("none"), { desc = "Delete the conflict region for the whole file" } } ``` -------------------------------- ### Configuring File History Panel Keybindings in Neovim Diffview (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet defines normal mode keybindings specific to the `diffview.nvim` file history panel. These bindings enable users to interact with commit history, open entries in diff views, copy commit hashes, restore files, and manage folds within the history view. ```Lua { "n", "g!", actions.options, { desc = "Open the option panel" } }, { "n", "", actions.open_in_diffview, { desc = "Open the entry under the cursor in a diffview" } }, { "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } }, { "n", "L", actions.open_commit_log, { desc = "Show commit details" } }, { "n", "X", actions.restore_entry, { desc = "Restore file to the state from the selected entry" } }, { "n", "zo", actions.open_fold, { desc = "Expand fold" } }, { "n", "zc", actions.close_fold, { desc = "Collapse fold" } }, { "n", "h", actions.close_fold, { desc = "Collapse fold" } }, { "n", "za", actions.toggle_fold, { desc = "Toggle fold" } }, { "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } }, { "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } }, { "n", "j", actions.next_entry, { desc = "Bring the cursor to the next file entry" } }, { "n", "", actions.next_entry, { desc = "Bring the cursor to the next file entry" } }, { "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } }, { "n", "", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } }, { "n", "", actions.select_entry, { desc = "Open the diff for the selected entry" } }, { "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry" } } ``` -------------------------------- ### Configuring Three-Way Diff Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md These Lua mappings define keybindings for three-way diff layouts in Diffview.nvim. They allow users to obtain diff hunks from 'ours' or 'theirs' versions of the file and access the help panel for view-specific assistance. ```Lua diff3 = { -- Mappings in 3-way diff layouts { { "n", "x" }, "2do", actions.diffget("ours"), { desc = "Obtain the diff hunk from the OURS version of the file" } }, { { "n", "x" }, "3do", actions.diffget("theirs"), { desc = "Obtain the diff hunk from the THEIRS version of the file" } }, { "n", "g?", actions.help({ "view", "diff3" }), { desc = "Open the help panel" } } } ``` -------------------------------- ### Advanced Keymap Definition with Multiple Modes and Arguments (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet demonstrates how to define more granular keymaps in Diffview.nvim using a list-like table format. This allows specifying multiple modes (e.g., normal and visual) and passing additional arguments to `vim.keymap.set()`, such as `silent` or `nowait`. ```Lua view = { -- Normal and visual mode mapping to vim command: { { "n", "v" }, "a", "echom 'foo'", { silent = true } }, -- Visual mode mapping to lua function: { "v", "b", function() print("bar") end, { nowait = true } } } ``` -------------------------------- ### Defining Custom Hooks in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet demonstrates how to define custom callback functions for various events emitted by Diffview.nvim. The `diff_buf_read` hook modifies local buffer options for diff buffers, while `view_opened` prints information when a new view is opened. ```Lua hooks = { diff_buf_read = function(bufnr) -- Change local options in diff buffers vim.opt_local.wrap = false vim.opt_local.list = false vim.opt_local.colorcolumn = { 80 } end, view_opened = function(view) print( ("A new %s was opened on tab page %d!") :format(view.class:name(), view.tabpage) ) end } ``` -------------------------------- ### Configuring Four-Way Diff Keybindings in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md These Lua mappings define keybindings for four-way diff layouts in Diffview.nvim. They enable users to obtain diff hunks from 'base', 'ours', or 'theirs' versions of the file and open the help panel for view-specific guidance. ```Lua diff4 = { -- Mappings in 4-way diff layouts { { "n", "x" }, "1do", actions.diffget("base"), { desc = "Obtain the diff hunk from the BASE version of the file" } }, { { "n", "x" }, "2do", actions.diffget("ours"), { desc = "Obtain the diff hunk from the OURS version of the file" } }, { { "n", "x" }, "3do", actions.diffget("theirs"), { desc = "Obtain the diff hunk from the THEIRS version of the file" } }, { "n", "g?", actions.help({ "view", "diff4" }), { desc = "Open the help panel" } } } ``` -------------------------------- ### Excluding Specific Paths in Diffview.nvim (Shell) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This command opens Diffview.nvim, excluding specified paths from the diff. Multiple paths can be excluded by prefixing each with `:!`. ```Shell DiffviewOpen -- :!exclude/this :!and/this ``` -------------------------------- ### Hiding Untracked Files with Diffview.nvim (Shell) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This command opens Diffview.nvim while hiding any untracked files from the diff view. It's useful for focusing only on changes to tracked files. ```Shell DiffviewOpen -uno ``` -------------------------------- ### Configuring Diagonal Lines for Diff Mode in Lua Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This Lua command appends a setting to the `fillchars` option, enabling diagonal lines (`╱`) for deleted lines in diff mode. This provides a visual cue for removed content, with alignment depending on the terminal. ```Lua vim.opt.fillchars:append { diff = "╱" } ``` -------------------------------- ### Configuring Diagonal Lines for Diff Mode in Vimscript Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This Vimscript command modifies the `fillchars` option to display diagonal lines (`╱`) in place of deleted lines in diff mode, improving visual clarity. The actual alignment depends on the terminal emulator. ```Vimscript set fillchars+=diff:╱ ``` -------------------------------- ### Disabling Default Keymaps in Diffview.nvim (Lua) Source: https://github.com/sindrets/diffview.nvim/blob/main/README.md This snippet shows how to disable specific default keymaps in Diffview.nvim. By setting the right-hand side of a keymap to `false`, both simple string-based mappings and more complex list-based mappings can be effectively deactivated. ```Lua view = { -- Disable the default normal mode mapping for ``: [""] = false, -- Disable the default visual mode mapping for `gf`: { "x", "gf", false } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.