How to use git from vim @vim conf2013

25
How to use Git from Vim 2013/11/16 VimConf 2013 cohama / @c0hama

Transcript of How to use git from vim @vim conf2013

Page 1: How to use git from vim @vim conf2013

How to use Git from Vim2013/11/16 VimConf 2013

cohama / @c0hama

Page 2: How to use git from vim @vim conf2013

cohama❖ Twitter @c0hama

❖ from Nagoya➢ Nagoya.vim

❖ vim-smartinput-endwise, the-ocamlspot.vim

❖ JavaScript, Ruby, OCaml, Haskell

About me

Page 3: How to use git from vim @vim conf2013

Git / Vim ?

Messed up...

Page 4: How to use git from vim @vim conf2013

Using Git from Vim

Life changing!!

Page 5: How to use git from vim @vim conf2013

Table of Contents1. Using Git from Vim (w/o any plugins)

2. Plugins for Git

3. Advanced usage

Page 6: How to use git from vim @vim conf2013

Table of Contents1. Using Git from Vim (w/o any plugins)

2. Plugins for Git

3. Advanced usage

Page 7: How to use git from vim @vim conf2013

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)

Page 8: How to use git from vim @vim conf2013

Getting ready to use

$ git config --global core.editor vim

# or

$ git config --global core.editor gvim -f

Page 9: How to use git from vim @vim conf2013

Using Git from command-line mode

● Just use :!

● Define key mapping (if you need)

:!git add %

:!git commit -m”commit message”

:!git checkout HEAD %

“ e.g.

nnoremap \ga :<C-u>!git add %<CR>

Page 10: How to use git from vim @vim conf2013

Editing commit message

:!git commit

Page 11: How to use git from vim @vim conf2013

Showing diff to be committed

:DiffGitCached

Page 12: How to use git from vim @vim conf2013

Editing rebase-interactive (rebase -i)

:!git rebase -i HEAD~3

Page 13: How to use git from vim @vim conf2013

Showing commit in rebase-interactive

K

Page 14: How to use git from vim @vim conf2013

Table of Contents1. Using Git from Vim (w/o any plug-ins)

2. Plugins for Git

3. Advanced usage

Page 15: How to use git from vim @vim conf2013

vim-fugitive fundamentals

:Gwrite git-add:Gcommit git-commit:Git xxx any git command

● These commands are performed in buffer directory.

Page 16: How to use git from vim @vim conf2013

:Gdiff (vim-fugitive)● git-diff by vimdiff

worktreeindex

Interactive “git add -p”

dp:diffput

Page 17: How to use git from vim @vim conf2013

:Gstatus (vim-fugitive)

<C-n> next file<C-p> prev file<CR> edit file- add/resetcc commitD diff

● git-status output as a new window.

Page 18: How to use git from vim @vim conf2013

gitv● gregsexton/gitv

○ gitk clone for Vim.○ viewing log history, change set and

refs.○ requires vim-fugitive.

Page 19: How to use git from vim @vim conf2013

:Gitv● showing repository’s history

difflog

Page 20: How to use git from vim @vim conf2013

:Gitv!● showing file’s history

file

log

Page 21: How to use git from vim @vim conf2013

Table of Contents1. Using Git from Vim (w/o any plugins)

2. Plugins for Git

3. Advanced usage

Page 22: How to use git from vim @vim conf2013

Advanced usage of gitv and fugitive

● Remember the gitv window.

● Get the hash of the current line.

SHA-1 hash!

matchstr(getline('.'), '\[\zs\x\+\ze\]$')

Page 23: How to use git from vim @vim conf2013

Advanced usage of gitv and fugitive

● Use :Git with the hash.

● Define key mappings

:Git rebase <hash>:Git reset --hard <hash>:Git checkout -b hoge <hash>…more

Page 24: How to use git from vim @vim conf2013

Demo

Page 25: How to use git from vim @vim conf2013

Conclusion1. It’s easy to use Git from Vim

2. vim-fugitive and gitv are wonderful.

3. Hacking gitv will change your life.