Skip to content

Instantly share code, notes, and snippets.

@kuri65536
Last active March 20, 2018 00:28
Show Gist options
  • Save kuri65536/812c62adf945fb9960a65d5c767e047c to your computer and use it in GitHub Desktop.
Save kuri65536/812c62adf945fb9960a65d5c767e047c to your computer and use it in GitHub Desktop.

Mercurial commit with vim three buffer window

write commit message with vim like TortoiseHg or another GUI style. viewing diffs and logs simultaneously.

commit message view of diff
view of commit logs

Usage

for mercurial

$ hgcommit [commit-files...]

for git

$ gitcommit [commit-files...]

Sample

Mercurial examples

all files

$ hgcommit

specified files.

$ hgcommit readme.md

Git examples

all files.

$ gitcommit -a

specified files.

$ git add readme.md
$ gitcommit

Another examples

finish to edit.

:x     " save commit comment buffer.
:cq    " quit another buffers. (diff and logs)

cancel to edit.

:cq!   " quit all buffers.

Screenshot = screenshot.png

Reference

function hgcommit() {
_VCSTGT=$(for i in $@; do echo $i; done) \
HGEDITOR="vim -c HgCommit" hg commit $*
}
function gitcommit() {
_VCSTGT=$(for i in $@; do echo $i; done) \
GIT_EDITOR="vim -c GitCommit" git commit $*
}
" commit {{{1
function! _vcs_commit(diff, logs)
let l:seq = []
for item in systemlist("echo $_VCSTGT")
if item=~#"^/"
continue
endif
if item=~#"^-"
continue
endif
call add(l:seq, item)
endfor
let l:cmd_diff = ':r!'.a:diff.join(l:seq, " ")
let l:cmd_logs = ':r!'.a:logs.join(l:seq, " ")
rightbelow vnew
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
execute(l:cmd_diff)
1
call append(line("."), l:cmd_diff)
wincmd h
rightbelow new
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
execute(l:cmd_logs)
1
call append(line("."), l:cmd_logs)
wincmd k
endfunction
command GitCommit call _vcs_commit('git diff --color=never --cached ',
\ 'git log ')
command HgCommit call _vcs_commit('hg diff --color=no ',
\ 'hg log --color=no -G -l 30 ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment