vimtricks.wiki Concise Vim tricks, one at a time.

How do I use Git from within Vim with vim-fugitive?

Answer

:Git command (e.g., :Git status)

Explanation

vim-fugitive by Tim Pope is a comprehensive Git wrapper for Vim. It lets you run Git commands and interact with Git features directly from Vim.

How it works

  • :Git (or :G) opens the Git status window
  • :Git commit creates a commit
  • :Git diff shows the diff
  • :Git blame annotates the current file with blame info

Example

:Git status     " View status in a buffer
:Git add %      " Stage the current file
:Git commit     " Open commit message editor
:Git push       " Push to remote
:Git blame      " Show blame annotations

Tips

  • Install: Plug 'tpope/vim-fugitive'
  • :Gdiffsplit shows a side-by-side diff
  • :GBrowse opens the file on GitHub (with vim-rhubarb)
  • In the status window, s stages, u unstages, cc commits
  • :Gread checks out the file from the index (reverts changes)

Next

How do you yank a single word into a named register?