tig ãªãã¦ç®ãããªãï¼ Git ã®ãã°ç³» Vim ãã©ã°ã¤ã³ gitv ï¼ gitv ãGit çµ±åã¤ã³ã¿ã¼ãã§ã¼ã¹åããæå¼·ã®è¨å®
ãã®è¨äºã¯ Vim Advent Calendar 2012 ã® 168 æ¥ç®ã®è¨äºã§ãã
æ¨æ¥ã¯ id:yonchu ããã® accelerated-smooth-scroll という Vimプラグイン を作った (Vim Advent Calendar 2012, 167日目) - よんちゅBlog ã§ããã
ã¯ããã«
æè¿ãGit ã®ãã°ãè¦ãç³»ã®ã¨ã³ããªãå¤ãæ°ããã¾ããä»åã® Vim Advent Calendar ã§ã
- はじめての unite source(unite-tig) - Design x Verification
- vac143 - YouTube
- Vimでgitのログをきれいに表示する - derisの日記
ã¨ããè¨äºãããã¾ããããã¾ãæè¿
ãªãããããã¾ããã
æµè¡ã£ã¦ãã®ããªï¼ï¼ï¼
ä»åã¯ç§ã Vim ä¸ã§ Git ã®ãã°ãè¦ã(+α)ã¨ãã©ããã£ã¦ããã«ã¤ãã¦æ¸ãã¾ãã
gitv!
gitv ã¨ãããã©ã°ã¤ã³ãããã¾ãã
ä¸ã®å³ã®ããã«å·¦å´ã« Git ã®ãã°ãå³å´ã«ãã®æã®ã³ãããã® diff ã表示ããã¾ãã便å©ï¼ï¼
ãªããgitv 㯠vim-fugitive ã«ä¾åãã¦ããã®ã§ vim-fugitive ã®ã¤ã³ã¹ãã¼ã«ã¯å¿
é ã§ãã
å®ã¯ gitv ã®ç´¹ä»è¨äºã¯åæ¸ãããã¨ãããã®ã§åºæ¬çãªãã¨ã¯ãã¡ããåç §ãã¦ãã ããã
gitv ã®ä½¿ãæ¹å¿ç¨ç·¨
ä»æ¥ã®ä¸»é¡ã¯ãã¡ãã§ãã
gitv ã¯ããã©ã«ãã®ã¾ã¾ã§ããã°ãè¦ãåã«ã¯ä¾¿å©ãªãã§ããããã以å¤ã®ãã¨ã¯ãã¾ãåºæ¥ã¾ããã*1
ããã§ãèªåã® vimrc ã« gitv ã便å©ã«ä½¿ãããã®è¨å®ã追å ãã¾ããããã«ãã gitv ãåãªããã°ãã¥ã¼ã¢ãã Git ã®ããã®çµ±åã¤ã³ã¿ã¼ãã§ã¼ã¹ã¸ã¨æè¯ããããã¨ãã§ãã¾ãã
ä¸æºå
ã¾ãæºåã¨ã㦠vimrc ã«ä»¥ä¸ã®è¨è¿°ã追å ãã¾ãã
autocmd FileType gitv call s:my_gitv_settings() function! s:my_gitv_settings() " ããã«è¨å®ãæ¸ã endfunction
*2
gitv ãéã㨠filetype=gitv ãè¨å®ãããã®ã§ããããå©ç¨ã㦠gitv ã®ãããã¡ã ãã§ä½¿ããç´ æµè¨å®ã追å ãã¦ããã¾ãã
以éãè¨å®ã¯ä¸ã® s:my_gitv_settings() é¢æ°å
ã«æ¸ãã¦ããã¾ãã
ç¾å¨ã®ã«ã¼ã½ã«ä½ç½®ã«ãããã©ã³ãåãåå¾ãã¦ãã°ä¸ã§ãã©ã³ãã« checkout ãã
gitv ã®ãã°ã«ã¯ãã©ã³ãåã表示ããã¾ãã*3ãã«ã¼ã½ã«ããã©ã³ãåã«åããã¦ããã®ãã©ã³ãåã«å¯¾ã㦠git checkout ã reset ãªã©ã®æä½ãã§ããã¨ä¾¿å©ã§ãã
ãã®ããã«ä»¥ä¸ã®è¨å®ã追å ãã¾ãã
" s:my_gitv_settings å setlocal iskeyword+=/,-,. nnoremap <silent><buffer> C :<C-u>Git checkout <C-r><C-w><CR>
ãã©ã³ãåã¯åãªãè±æ°åã ãã§ãªã / ã - ã¨ãã£ãè¨å·ã使ããã®ã§ãã¾ãã¯ãããããã¼ã¯ã¼ãã¨ãã¦å«ãã¾ãã
ã³ãã³ãã¢ã¼ã㧠<C-r><C-w> ãå
¥åããã¨ã«ã¼ã½ã«ã®ä¸ã«ãããã¼ã¯ã¼ããåå¾ã§ãããã¨ãå©ç¨ãã¦ãGit ã®ã³ãã³ããçµã¿ç«ã¦ã¾ãã
ãªãã:Git ã¨ããã³ãã³ã㯠vim-fugitive ãæä¾ãã¦ããã³ãã³ãã§ãã*4
ãã®ä¾ã ã¨ããã©ã³ãåã®ä¸ã§ C ãæ¼ãã¨å³åº§ã«ãã®ãã©ã³ãã« git checkout ãããã¨ãã§ãã¾ãã
checkout ã®ã¨ãããããããå¤ããã°ãã©ã³ãåãå©ç¨ããä»»æã®ã³ãã³ããããã«å®è¡ãããã¨ãã§ãã¾ãã
ã¡ãªã¿ã«ãã«ã¼ã½ã«ã移åãããã¨ã㯠r ã R ãå©ç¨ããã¨ãã©ã³ãã®éãç°¡åã«ç§»åã§ãã¾ãã
ç¾å¨ã®ã«ã¼ã½ã«è¡ã® SHA1 ããã·ã¥ãåå¾ãã¦ãã°ä¸ã§ãããããã¨ãå®è¡ãã
ã¶ã£ã¡ãã Git ã¯ããã·ã¥ãå ¨ã¦ã§ããããã·ã¥ã®å¤ããåå¾åºæ¥ãã°å²ã¨ãªãã§ãåºæ¥ã¾ãããã¡ãã¡ãHEAD ããããã¤é¢ãã¦ããããæ°ããå¿ è¦ã¯ããã¾ããã
幸ããgitv ã®ã¦ã£ã³ãã¦ã«ã¯ããã·ã¥å¤ãä¸çªå³ã«è¡¨ç¤ºããã¦ãã¾ãã表示ããã¦ããã°åå¾ããã®ã¯ç°¡åã§ãã
" ããã¯å¤ã«å®ç¾©! function! s:gitv_get_current_hash() return matchstr(getline('.'), '\[\zs.\{7\}\ze\]$') endfunction
ãã®é¢æ°ããããã¬ãã«ã«æ¸ãã¦ããã¾ãã
ãã¨ã¯ããã㨠expression ã¬ã¸ã¹ã¿*5ãå©ç¨ã㦠Git ã®ã³ãã³ããçµã¿ç«ã¦ã¾ãã
" s:my_gitv_settings å nnoremap <buffer> <Space>rb :<C-u>Git rebase <C-r>=GitvGetCurrentHash()<CR><Space> nnoremap <buffer> <Space>R :<C-u>Git revert <C-r>=GitvGetCurrentHash()<CR><CR> nnoremap <buffer> <Space>h :<C-u>Git cherry-pick <C-r>=GitvGetCurrentHash()<CR><CR> nnoremap <buffer> <Space>rh :<C-u>Git reset --hard <C-r>=GitvGetCurrentHash()<CR>
ãããã®è¨å®ã«ãããã«ã¼ã½ã«ä½ç½®ã®ã³ãããã«å¯¾ã㦠rebase, revert, cherry-pick, reset ãªã©ã®ã³ãã³ããå®è¡ãããã¨ãã§ãã¾ãããã¡ãããã以å¤ã§ããªãã¸ã§ã³*6ãæå®ããã³ãã³ãã¯ããã¦ãå¯è½ã§ãã
ãã®è¨å®ã¯é常ã«å¼·åã§ããæ¥å¸¸ã® add, commit ãªã©ã¯ fugitive ãã(ãã¡ãã Vim ã®ãããã³ã°ãå©ç¨ãã¦)å®è¡ããrebase ã reset ãªã©ãã©ã³ãã使ãã³ãã³ãã gitv ããç°¡åã«è¡ãããã«ããã¨ãã»ã¼ã·ã§ã«ã§ git ã³ãã³ããå©ããã¨ããªããªãã¾ãã
便å©ãããã®ã§ãããæ¥çªç¶ã®èªåã® Vim ã使ããªããªã£ãæã«é常ã«ã¹ãã¬ã¹ã«ãªãã®ã§æ³¨æãã¾ãããã
ãã¡ã¤ã«ã® diff ãããªãã¦å¤æ´ããããã¡ã¤ã«ã®ä¸è¦§ãè¦ãã
gitv ã ããããªã tig ãªããã§ããã°ã¨ä¸ç·ã«ãã¡ã¤ã«ã®å·®åã表示ããã¦ãã¾ããã§ãæã«ã¯ãã¡ã¤ã«ã®ä¸èº«ãããã©ã®ãã¡ã¤ã«ãå¤æ´ããããã®æ¹ãéè¦ãªå ´åãããã¾ããããããæã«ã該å½ã®ã³ãããã§å¤æ´ããããã¡ã¤ã«ã®ä¸è¦§ãåå¾åºæ¥ãã°ä¾¿å©ã§ãã
å®ã¯ããã®è¡¨ç¤ºããã¦ãã diff ã¯ãã¡ã¤ã«åã®é¨åã§æãããããããã«ãªã£ã¦ãã¾ããããªãã¡ããã¹ã¦ã®æãããã¿ãéãããã¨ã§ãã¡ã¤ã«ä¸è¦§ã表示ãããã¨ãå¯è½ã¨ãªãã¾ãã
ãã®æãããã¿ãç°¡åã«æä½ã§ããããã«ã以ä¸ã®è¨å®ããããã¬ãã«ã«è¿½å ãã¾ãã
autocmd FileType git setlocal nofoldenable foldlevel=0 function! s:toggle_git_folding() if &filetype ==# 'git' setlocal foldenable! endif endfunction
ããã¦ä»¥ä¸ã®è¨å®ã s:my_gitv_settings é¢æ°å ã«è¿½å ãã¾ãã
" s:my_gitv_settings å nnoremap <silent><buffer> t :<C-u>windo call <SID>toggle_git_folding()<CR>1<C-w>w
ããã«ãããt ãã¼ãæ¼ãã ãã§ãã¹ã¦ã® diff ã®ã¦ã£ã³ãã¦ã«å¯¾ã㦠folding ãåãæ¿ãã¾ããã¤ã¾ãããã¡ã¤ã«ã® diff ã¨ãã¡ã¤ã«ã®ä¸è¦§ãåãæ¿ãããã¨ãã§ãã¾ãã
ã¡ãªã¿ã«ãfugitive ã nice 㪠foldtext ãæä¾ãã¦ããã®ã§ãã¡ã¤ã«åã ããããªãã¦ä½è¡å¤æ´ããã£ããã表示ããã¾ãã*7
ã¾ã¨ã
fugitive 㨠gitv ã®çµã¿åããããã¨ã«ãã£ã¦ãGit ã®ããã¦ãã®ä½æ¥ã Vim å
ã§å®çµããããã¨ãã§ãã¾ãã
æ
£ãéããã¨ã·ã§ã«ã§ git ã³ãã³ããå©ãã®ãè¦çã«ãªãã®ã§æ³¨æã
ææ¥ã¯ @s_of_p ããã§ãã
*1:checkout ã merge ãã§ãã¾ããã¤ã³ã¿ã¼ãã§ã¼ã¹ãé常ã«ã¢ã¬
*2:ä¾ãæ¸ãã¨ãã¦ãªãã§ãããautocmd ã«ã¯ augroup ã¨ãã¤ã㦠vimrc ããªãã¼ããã«ã«ãã¾ããã
*3:ãã¹ã¦ã®ãã©ã³ãã表示ããã«ã¯ :Gitv --all ã¨ãã¾ã
*4:å®ã¯ãgitv ä¸ã§ :Git ã¯ä¸æ¸ãããã¦ã㦠fugitive ã® :Git ãå¼ã³åºããå¾ãèªåèªèº«ãæ´æ°ãã¾ã
*5:ã¤ã³ãµã¼ãã»ã³ãã³ãã¢ã¼ãã§<C-r>=ãå ¥åãããã¨ã«ãã Vim ã®å¼ã®çµæãæ¿å ¥ã§ãã¾ãã:help quote=
*6:ãã©ã³ãåã¨ã HEAD^ ã¨ãããã¨ãªãã ã£ãï¼
*7:foldtext ãèªåã§ã«ã¹ã¿ãã¤ãºãã¦ãå ´å㯠autocmd FileType git setlocal foldtext=fugitive#foldtext()ããã¨æ²»ãã¾ãã