vim-fugitive

repository·master·Indexed 12 days ago

https://github.com/tpope/vim-fugitive

A Vim plugin for Git integration that allows users to run Git commands, manage the index, and explore repository history directly within Vim. It provides the :Git command for arbitrary operations, specialized commands like :Gedit, :Gdiffsplit, and :Gread for object database interaction, and file management tools such as :GMove, :GDelete, and :GRename.

Tokens
968
Snippets
4
Records
6
Agent score
48%

What's inside Fugitive

  1. Perform Git file operations with :GMove, :GDelete, and :GRename

    master

    Use these commands to manage files within the Git index and working directory:

    • :GMove: Performs a git mv on the current file and updates the buffer name to match.
    • :GRename: Performs a git mv with a destination filename relative to the current file's directory.
    • :GDelete: Performs a git rm on the current file and deletes the buffer.
    • :GRemove: Performs a git rm on the current file but leaves the (now empty) buffer open.
    • :Gwrite: Writes to both the work tree and index versions of a file.
  2. Manage files and history with :Gedit, :Gdiffsplit, and :Gread

    master

    Fugitive provides high-level commands for interacting with the Git object database and the index:

    • :Gedit / :Gsplit: View any blob, tree, commit, or tag. Example: :Gedit HEAD~3:% loads the current file as it existed 3 commits ago.
    • :Gdiffsplit / :Gvdiffsplit: Opens a side-by-side diff between the staged version of the file and the working tree version. You can use Vim's diff tools to apply changes to the staged version and write the buffer to stage them. You can also pass an argument to :Gedit to diff against specific historical versions.
    • :Gread: A variant of git checkout -- filename that operates on the buffer instead of the file. This allows you to use u to undo the operation and avoids warnings about files changing outside Vim.
    • :Gwrite: Writes to both the work tree and index versions of a file (similar to git add when in a work tree, or git checkout when in the index/blob).
    :Gedit HEAD~3:%
  3. Search and Browse Git content

    master

    Fugitive includes commands for searching and web integration:

    • :Ggrep: Runs git grep using Vim's :grep interface.
    • :Glgrep: Runs git grep using Vim's :lgrep interface.
    • :GBrowse: Opens the current file in the web front-end of your hosting provider (e.g., GitHub, GitLab). You can use this in visual mode to specify a line range. This requires compatible plugins for your specific provider (e.g., vim-rhubarb for GitHub).
  4. Install fugitive.vim

    master

    You can install Fugitive using your preferred Vim package manager or via Vim's built-in package support by cloning the repository into your pack directory.

    mkdir -p ~/.vim/pack/tpope/start
    cd ~/.vim/pack/tpope/start
    git clone https://tpope.io/vim/fugitive.git
    vim -u NONE -c "helptags fugitive/doc" -c q
  5. Use the :Git command for arbitrary Git operations

    master

    The :Git (or :G) command is the primary interface for Fugitive. It allows you to run any arbitrary Git command directly from Vim. It improves upon :!git with several specialized behaviors:

    • Quiet Commands: Commands like :Git add do not trigger the "Press ENTER or type command to continue" prompt.
    • In-Vim Editing: Commands that normally invoke an editor (like :Git commit or :Git rebase -i) will open the editor within your current Vim instance.
    • Paginated Output: Verbose commands like :Git diff or :Git log are loaded into a temporary buffer. You can force this behavior using :Git --paginate or :Git -p.
    • Blame Mode: :Git blame opens a temporary buffer with maps. Pressing Enter on a line shows the commit that changed it; press g? to see other maps. If no filename is provided, it blames the current file in a vertical, scroll-bound split.
    • Quickfix Integration: :Git mergetool and :Git difftool load changesets into the quickfix list.
    • Summary Window: Running :Git with no arguments opens a summary window showing dirty files, unpushed commits, and unpulled commits. Press g? in this window to see a list of maps for diffing, staging, committing, rebasing, and stashing.
    :Git