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 commitcreates a commit:Git diffshows the diff:Git blameannotates 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' :Gdiffsplitshows a side-by-side diff:GBrowseopens the file on GitHub (with vim-rhubarb)- In the status window,
sstages,uunstages,cccommits :Greadchecks out the file from the index (reverts changes)