Skip to content

Leaderf git

Yggdroot edited this page Jul 10, 2024 · 39 revisions

About

Leaderf git is a plugin focused on offering a smooth, intuitive, and efficient Git experience within Vim. It helps developers enhance their productivity and streamline their workflow.

Requirements

  • git command is available.
  • Vim or Neovim supports Python.

Why

  • Ease Of Use

    Leaderf git stands out for its simplicity and ease of use. Its straightforward commands allow developers to perform Git operations directly within Vim without needing extensive learning or setup. This makes it accessible even to those who are new to Git or Vim.

  • Efficient Navigation

    Leaderf git utilizes advanced search functionalities, including fuzzy search, to rapidly locate specific commits, files, and changes within the repository. This accelerates navigation through codebases, reducing the time spent searching for relevant information.

  • Intuitive Diff View

    Leaderf git offers multiple viewing options for changes, such as side-by-side comparisons and unified views. These features allow developers to quickly assess and understand code changes without delays, enhancing productivity during code reviews and troubleshooting.

  • High Performance

    Leaderf git is optimized for performance, handling large repositories with ease. Its asynchronous command execution and optimized algorithms ensure Git operations are executed swiftly and responsively.

Features

Leaderf git diff

usage: Leaderf[!] git diff [-h] [--cached] [--directly | --explorer] [--position <POSITION>]
                           [--navigation-position <POSITION>] [-s | -u] [--current-file]
                           [extra ...]
options:
  -h, --help            show this help message and exit
specific arguments:
  --cached, --staged    run 'git diff --cached'
  --directly            output the changes directly
  --explorer            view changed files in a tree explorer
  --position <POSITION>
                        specifies the position of the changes window
  --navigation-position <POSITION>
                        specifies the position of the navigation panel
  -s, --side-by-side    show changes in a side-by-side view
  -u, --unified         show changes in a unified view
  --current-file        show changes of current file
  extra                 extra arguments of git diff
  • :Leaderf git diff --directly

    It is the same as running git diff in the command line.

  • :Leaderf git diff

    Fuzzy search a file to view the changes.

    Leaderf.git.diff.mp4

    Use :Leaderf git diff --recall to resume the fuzzy search.
    In the diff file, ]c is used to jump to the next change, [c is used to jump to the previous change, <CR> is used to jump to the corresponding file to edit it.
    To customize the shortcut keys, for example,

    let g:Lf_GitKeyMap = {
              \ 'previous_change': '<C-N>',
              \ 'next_change': '<C-P>',
              \ 'edit_file': 'e',
              \ }
  • :Leaderf git diff --side-by-side

    Fuzzy search a file to view the changes in a side-by-side view.

    Leaderf.git.diff.--side-by-side.mp4

    In the diff file, ]c is used to jump to the next change, [c is used to jump to the previous change, <CR> is used to jump to the corresponding file to edit it.
    To customize the shortcut keys, for example,

    let g:Lf_GitKeyMap = {
              \ 'previous_change': '<C-N>',
              \ 'next_change': '<C-P>',
              \ 'edit_file': 'e',
              \ }
  • :Leaderf git diff --explorer

    Open an explorer tabpage to view the changes.

    Leaderf.git.diff.--explorer.mp4

    Press <F1> for help.

    image

    In the navigation panel, type f to start a fuzzy search and type F to resume the previous fuzzy search.

    fuzzy.search.mp4

    By default, the diff view is in side-by-side mode, so this command is the same as :Leaderf git diff --explorer --side-by-side.
    To change the default diff view mode, let g:Lf_GitDiffViewMode = 'unified', now this command is the same as :Leaderf git diff --explorer --unified.

  • :Leaderf git diff --explorer --unified

    View the changes in a unified view.

    image

    To highlight the line numbers, :let g:Lf_GitHightlightLineNumber = 1

    image

    In the navigation panel, type s to switch between unified view and side-by-side view.

    switch.between.unified.and.side-by-side.mp4

    Select different diff algorithm:

    diff.algorithm.mp4
  • :LeaderfGitSplitDiff

    It is a shortcut of :Leaderf git diff --current-file --side-by-side.
    It is a bit similar to DiffOrig.

  • :Leaderf git diff [options] [extra ...]

    [extra ...] is options supported by the native git diff command.
    For example, :Leaderf git diff <commit> <commit> is equivalent to git diff <commit> <commit>, it's to view the changes between two arbitrary <commit>.
    For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in gitrevisions(7).

Leaderf git log

usage: Leaderf[!] git log [-h] [--current-file | --current-line] [--directly | --explorer]
                          [--position <POSITION>] [--navigation-position <POSITION>] [-s | -u]
                          [-n <number>] [--skip <number>] [--since <date>] [--until <date>]
                          [--author <pattern>] [--committer <pattern>] [--no-merges] [--all] [--graph]
                          [--reverse-order] [--find-copies-harder] [extra ...]
options:
  -h, --help            show this help message and exit
specific arguments:
  --current-file        show logs of current file
  --current-line        show logs of current line
  --directly            output the logs directly
  --explorer            view changed files of one commit in a tree explorer
  --position <POSITION>
                        specifies the position of the logs window
  --navigation-position <POSITION>
                        specifies the position of the navigation panel
  -s, --side-by-side    show changes in a side-by-side view
  -u, --unified         show changes in a unified view
  -n <number>, --max-count <number>
                        Limit the number of commits to output.
  --skip <number>       Skip number commits before starting to show the commit output.
  --since <date>, --after <date>
                        Show commits more recent than a specific date.
  --until <date>, --before <date>
                        Show commits older than a specific date.
  --author <pattern>    Limit the commits output to ones with author header lines that match the
                        specified pattern (regular expression).
  --committer <pattern>
                        Limit the commits output to ones with committer header lines that match the
                        specified pattern (regular expression).
  --no-merges           Do not print commits with more than one parent.
  --all                 Pretend as if all the refs in refs/, along with HEAD, are listed on the command
                        line as <commit>.
  --graph               Draw a text-based graphical representation of the commit history on the left hand
                        side of the output.
  --reverse-order       Output the commits chosen to be shown in reverse order.
  --find-copies-harder  This flag makes the command inspect unmodified files as candidates for the source
                        of copy.
  extra                 extra arguments of git log
  • :Leaderf git log --directly

    It is the same as running git log in the command line.

  • :Leaderf git log

    Fuzzy search a commit and view the changes.

    Leaderf.git.log.mp4
  • :Leaderf git log --explorer

    Fuzzy search a commit and view the changes in an explorer tabpage.

    Leaderf.git.log.--explorer.mp4

    By default, the diff view is in side-by-side mode, so this command is the same as :Leaderf git log --explorer --side-by-side.
    To change the default diff view mode, let g:Lf_GitDiffViewMode = 'unified', now this command is the same as :Leaderf git log --explorer --unified.

  • :Leaderf git log --explorer --unified

    Fuzzy search a commit and view the changes in an explorer tabpage in unified mode.

    Leaderf.git.log.--explorer.--unified.mp4
  • :Leaderf git log [options] --current-file

    Explore the revision history of current file.

    Leaderf.git.log.--explorer.--current-file.mp4
  • :Leaderf git log [options] --current-line

    Explore the revision history of current cursor line.

    Leaderf.git.log.--current-line.mp4

Leaderf git blame

usage: Leaderf[!] git blame [-h] [-w] [--date <format>] [--inline]
options:
  -h, --help            show this help message and exit
specific arguments:
  -w                    Ignore whitespace when comparing the parent’s version and the child’s to find
                        where the lines came from.
  --date <format>       Specifies the format used to output dates. .i.e, git blame --date=<format>.
                        <format> can be one of ['relative', 'local', 'iso', 'iso-strict', 'rfc', 'short',
                        'default']
  --inline              Display inline git blame information.
  • :Leaderf git blame

    Open the git blame viewer.

    Leaderf.git.blame.mp4

    Once the blame panel is open, the following commands are available:

    <F1>:          toggle the help
    o:             show the details of current commit in an explorer page
    <CR>:          show the details of current commit in an explorer page
    <2-LeftMouse>: show the details of current commit in an explorer page
    h:             blame the parent commit of this line
    l:             go to the previous blame status
    m:             show the commit message
    p:             preview the diffs around the current line
    q:             quit the blame window

    The date of each change is highlighted in colors from cold to hot, providing a visual representation of the age of the changes. Cold colors (e.g., blue) indicate older changes, while hot colors (e.g., red) indicate more recent changes. This helps you quickly identify how recent each change is.

    It is easy to determine which commit last modified a specific line. However, finding the initial commit that introduced this line is not as straightforward in the command line. Fortunately, Leaderf git blame simplifies this process with the h, l, and p commands, allowing developers to easily trace back and identify the initial commit that introduced a line, making it easier to understand the history and evolution of the codebase.

  • :Leaderf git blame --date <format>

    Specify the date format to view the git blame infomation.
    The supported formats are: relative, local, iso, iso-strict, rfc, short, and default.
    The formats are the same as defined here.

    Leaderf.git.blame.--date.mp4
  • :Leaderf git blame --inline

    Show inline blame.

    Leaderf.git.blame.--inline.mp4

    Some commands are provided for inline blame:

    Command Decription
    :LeaderfGitInlineBlameEnable Enable inline blame. This command is a shortcut of :Leaderf git blame --inline.
    :LeaderfGitInlineBlameDisable Disable inline blame.
    :LeaderfGitInlineBlameToggle Toggle inline blame.
    :LeaderfGitInlineBlameUpdate If the file is updated in the git repository, we need to use this command to update the inline blame.

    By default, inline blame is not enabled, to enable it: let g:Lf_GitInlineBlameEnable = 1.

    The time format in blame information can be customized using g:Lf_GitBlameTimeFormat. This variable is a string that follows the same format as used by strftime(). For example, you can set it to '%Y-%m-%d %H:%M:%S'.

Leaderf git

:Leaderf git opens a command panel to display a list of frequently used commands. You can perform a fuzzy search to find and execute a specific command.

image

The commands displayed can be customized using g:Lf_GitCommands. For example,

let g:Lf_GitCommands = [
                    \ {"Leaderf git diff":                "fuzzy search and view the diffs"},
                    \ {"Leaderf git diff --cached":       "fuzzy search and view `git diff --cached`"},
                    \ {"Leaderf git diff HEAD":           "fuzzy search and view `git diff HEAD`"},
                    \ {"Leaderf git diff --side-by-side": "fuzzy search and view the side-by-side diffs"},
                    \ ]

Reference

git diff
git log
git blame

Clone this wiki locally