Add git support for vim using fugitive
Leipzig
Add git support for vim using fugitive #
Git wrapper plugin by Tim Pope: tpope/vim-fugitive
%expands to the full path of the current file
| command | note |
|---|---|
| :Git | run an arbitrary git command, shortcut: :G {args} |
| :Gwrite | stage file to the index |
like :Git add % |
|
| :Gread | revert file |
like :Git checkout % |
|
| :Gremove | delete file & vim buffer |
like :Git rm % |
|
| :Gmove | rename file & vim buffer |
like :Git mv % |
|
| :Gcommit | opens commit window (interactive status: C) |
| :Gblame | opens window containing annotations for each line of the file |
| :Gpush | invoke git push |
| :Gpull | invoke git pull |
| :Gstatus | invoke git status, shortcut: :G |
| :Gdiff | invoke git diff (interactive status: D) |
:Git #
- run an arbitrary git command
- aliases work just fine
:Git branch
:Git br
// .gitconfig
[alias]
br = branch
:Gstatus #
- shortcut
:G, likegit status - interactive split window
- navigate between listed files:
ctrl-nnext filectrl-pprev filegujump to unstaged sectiongsjump to staged sectiongUjump to untracked section
- stage / unstage file under cursor
-toggle: to add / remove a file from the indexsstage unstaged file: add to the index likegit adduunstage staged file: remove from the index likegit reset
- works in visual mode as well (select multiple files and press
-) - if you want to add all files use
:git add . - press
<Enter>to open current file (review it before adding)- press
oto open current file in a new horizontal split - press
gOto open current file in a new vertical split - press
Oto open current file in a tab
- press
:Gwrite #
- stage file to the index like
:Git add %orgit add <file> - adds all changes in that file to the index by default
vimconfig example #
nnoremap <silent> <leader>gs :Gstatus<CR><C-w>20+
nnoremap <silent> <leader>gd :Gdiff<CR><C-w>20+
nnoremap <silent> <leader>gc :Gcommit<CR><C-w>20+
nnoremap <silent> <leader>gw :Gwrite<CR><C-w>20+
nnoremap <silent> <leader>gp :Gpush<CR><C-w>20+
manage index, commit and push #
,gs/:Gto show git status-to add/remove file to the indexDto get the diff for the selected fileccto enter commit message (iinsert mode, write message, leave:wq),gp/:Gpushpush to current branch