Skip to content

Leaderf git

Yggdroot edited this page Jul 4, 2024 · 42 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] [--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
  --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 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.

    To fully comprehend the history and context of code, it's essential to identify the initial author of a specific line rather than just the last modifier. While it is easy to determine who last modified a specific line, finding the initial author 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 author.

  • :Leaderf git blame --date <format>

  • :Leaderf git blame --inline

Clone this wiki locally