Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
How to use Git from Vim
2013/11/16 VimConf 2013
cohama / @c0hama
About me
cohama
❖ Twitter @c0hama
❖ from Nagoya
➢ Nagoya.vim
❖ vim-smartinput-endwise, theocamlspot.vim
❖ JavaScript, Ruby...
Git / Vim ?

Messed up...
Using Git from Vim

Life changing!!
Table of Contents
1. Using Git from Vim (w/o any plugins)
2. Plugins for Git
3. Advanced usage
Table of Contents
1. Using Git from Vim (w/o any plugins)
2. Plugins for Git
3. Advanced usage
Using Git from Vim w/o any plugins
● At first, use Git from default Vim!
● Why?
○ learn about natural Vim power.
○ too man...
Getting ready to use

$ git config --global core.editor vim
# or
$ git config --global core.editor gvim -f
Using Git from command-line mode
● Just use :!
:!git add %
:!git commit -m”commit message”
:!git checkout HEAD %

● Define...
Editing commit message
:!git commit
Showing diff to be committed
:DiffGitCached
Editing rebase-interactive (rebase -i)
:!git rebase -i HEAD~3
Showing commit in rebase-interactive
K
Table of Contents
1. Using Git from Vim (w/o any plug-ins)
2. Plugins for Git
3. Advanced usage
vim-fugitive fundamentals
● These commands are performed in
buffer directory.
:Gwrite git-add
:Gcommit git-commit
:Git xxx...
:Gdiff (vim-fugitive)
● git-diff by vimdiff

dp
:diffput

index
Interactive “git add -p”

worktree
:Gstatus (vim-fugitive)
● git-status output as a new window.
<C-n> next file
<C-p> prev file
<CR> edit file
add/reset
cc
c...
gitv
● gregsexton/gitv
○ gitk clone for Vim.
○ viewing log history, change set and
refs.
○ requires vim-fugitive.
:Gitv
● showing repository’s history

log

diff
:Gitv!
● showing file’s history

log

file
Table of Contents
1. Using Git from Vim (w/o any plugins)
2. Plugins for Git
3. Advanced usage
Advanced usage of gitv and fugitive
● Remember the gitv window.
SHA-1 hash!

● Get the hash of the current line.
matchstr(...
Advanced usage of gitv and fugitive
● Use :Git with the hash.
:Git rebase <hash>
:Git reset --hard <hash>
:Git checkout -b...
Demo
Conclusion
1. It’s easy to use Git from Vim
2. vim-fugitive and gitv are wonderful.
3. Hacking gitv will change your life.
Upcoming SlideShare
Loading in …5
×

How to use git from vim @vim conf2013

3,968 views

Published on

Published in: Technology, Art & Photos
  • Be the first to comment

How to use git from vim @vim conf2013

  1. 1. How to use Git from Vim 2013/11/16 VimConf 2013 cohama / @c0hama
  2. 2. About me cohama ❖ Twitter @c0hama ❖ from Nagoya ➢ Nagoya.vim ❖ vim-smartinput-endwise, theocamlspot.vim ❖ JavaScript, Ruby, OCaml, Haskell
  3. 3. Git / Vim ? Messed up...
  4. 4. Using Git from Vim Life changing!!
  5. 5. Table of Contents 1. Using Git from Vim (w/o any plugins) 2. Plugins for Git 3. Advanced usage
  6. 6. Table of Contents 1. Using Git from Vim (w/o any plugins) 2. Plugins for Git 3. Advanced usage
  7. 7. Using Git from Vim w/o any plugins ● At first, use Git from default Vim! ● Why? ○ learn about natural Vim power. ○ too many plug-ins is too complex. ○ forbidden to access github.com. (It’ me)
  8. 8. Getting ready to use $ git config --global core.editor vim # or $ git config --global core.editor gvim -f
  9. 9. Using Git from command-line mode ● Just use :! :!git add % :!git commit -m”commit message” :!git checkout HEAD % ● Define key mapping (if you need) “ e.g. nnoremap ga :<C-u>!git add %<CR>
  10. 10. Editing commit message :!git commit
  11. 11. Showing diff to be committed :DiffGitCached
  12. 12. Editing rebase-interactive (rebase -i) :!git rebase -i HEAD~3
  13. 13. Showing commit in rebase-interactive K
  14. 14. Table of Contents 1. Using Git from Vim (w/o any plug-ins) 2. Plugins for Git 3. Advanced usage
  15. 15. vim-fugitive fundamentals ● These commands are performed in buffer directory. :Gwrite git-add :Gcommit git-commit :Git xxx any git command
  16. 16. :Gdiff (vim-fugitive) ● git-diff by vimdiff dp :diffput index Interactive “git add -p” worktree
  17. 17. :Gstatus (vim-fugitive) ● git-status output as a new window. <C-n> next file <C-p> prev file <CR> edit file add/reset cc commit D diff
  18. 18. gitv ● gregsexton/gitv ○ gitk clone for Vim. ○ viewing log history, change set and refs. ○ requires vim-fugitive.
  19. 19. :Gitv ● showing repository’s history log diff
  20. 20. :Gitv! ● showing file’s history log file
  21. 21. Table of Contents 1. Using Git from Vim (w/o any plugins) 2. Plugins for Git 3. Advanced usage
  22. 22. Advanced usage of gitv and fugitive ● Remember the gitv window. SHA-1 hash! ● Get the hash of the current line. matchstr(getline('.'), '[zsx+ze]$')
  23. 23. Advanced usage of gitv and fugitive ● Use :Git with the hash. :Git rebase <hash> :Git reset --hard <hash> :Git checkout -b hoge <hash> …more ● Define key mappings
  24. 24. Demo
  25. 25. Conclusion 1. It’s easy to use Git from Vim 2. vim-fugitive and gitv are wonderful. 3. Hacking gitv will change your life.

×