Created
September 30, 2009 09:27
-
-
Save cho45/197936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" git で現在開いているファイルの前回の変更を開く。(require metarw-git) | |
nnoremap <silent> eg :<C-u>call <SID>git_prev_rev()<CR> | |
function! s:git_prev_rev() | |
let path = expand('%') | |
let commit = "HEAD" | |
let l = matchlist(path, 'git:\([^:]\+\):\([^:]\+\)') | |
if len(l) > 0 | |
let commit = l[1] | |
let path = l[2] | |
endif | |
let output = system(printf("git log -n 2 --pretty=format:'%%h %%s' HEAD~1000..%s -- %s", | |
\ shellescape(commit), | |
\ shellescape(path))) | |
if v:shell_error != 0 | |
echoerr 'git log failed with the following reason:' | |
echoerr output | |
return | |
endif | |
let commits = split(output, "\n") | |
let prev = commits[1] | |
let [commit_id, subject] = matchlist(prev, '^\(\S*\)\s\(.*\)$')[1:2] | |
let cursor = getpos(".") | |
silent edit `=printf('git:%s:%s', commit_id, path)` | |
call setpos('.', cursor) | |
echo subject | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment