how to use git from vim @vim conf2013
TRANSCRIPT
How to use Git from Vim2013/11/16 VimConf 2013
cohama / @c0hama
cohama❖ Twitter @c0hama
❖ from Nagoya➢ Nagoya.vim
❖ vim-smartinput-endwise, the-ocamlspot.vim
❖ JavaScript, Ruby, OCaml, Haskell
About me
Git / Vim ?
Messed up...
Using Git from Vim
Life changing!!
Table of Contents1. Using Git from Vim (w/o any plugins)
2. Plugins for Git
3. Advanced usage
Table of Contents1. 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 many plug-ins is too complex.○ forbidden to access github.com.
(It’ me)
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 :!
● 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>
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 Contents1. Using Git from Vim (w/o any plug-ins)
2. Plugins for Git
3. Advanced usage
vim-fugitive fundamentals
:Gwrite git-add:Gcommit git-commit:Git xxx any git command
● These commands are performed in buffer directory.
:Gdiff (vim-fugitive)● git-diff by vimdiff
worktreeindex
Interactive “git add -p”
dp:diffput
: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.
gitv● gregsexton/gitv
○ gitk clone for Vim.○ viewing log history, change set and
refs.○ requires vim-fugitive.
:Gitv● showing repository’s history
difflog
:Gitv!● showing file’s history
file
log
Table of Contents1. 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.
● Get the hash of the current line.
SHA-1 hash!
matchstr(getline('.'), '\[\zs\x\+\ze\]$')
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
Demo
Conclusion1. It’s easy to use Git from Vim
2. vim-fugitive and gitv are wonderful.
3. Hacking gitv will change your life.