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-n
next filectrl-p
prev filegu
jump to unstaged sectiongs
jump to staged sectiongU
jump to untracked section
- stage / unstage file under cursor
-
toggle: to add / remove a file from the indexs
stage unstaged file: add to the index likegit add
u
unstage 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
o
to open current file in a new horizontal split - press
gO
to open current file in a new vertical split - press
O
to 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
/:G
to show git status-
to add/remove file to the indexD
to get the diff for the selected filecc
to enter commit message (i
insert mode, write message, leave:wq
),gp
/:Gpush
push to current branch