Vim - show diff on commit in mercurial;

Posted by JackLeo on Stack Overflow See other posts from Stack Overflow or by JackLeo
Published on 2011-11-04T12:43:33Z Indexed on 2012/07/08 9:16 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

In my .hgrc I can provide an editor or a command to launch an editor with options on commit.

I want to write a method or alias that launches $ hg ci, it would not only open up message in Vim, but also would split window and there print out $ hg diff.

I know that I can give parameters to vim by using +{command} option. So launching $ vim "+vsplit" does the split but any other options goes to first opened window. So I assume i need a specific function, yet I have no experience in writing my own Vim scripts.

The script should:

  • Open new vertical split with empty buffer (with vnew possibly)
  • In empty buffer launch :.!hg diff
  • Set empty buffer file type as diff :set ft=diff

I've written such function:

function! HgCiDiff()
    vnew
    :.!hg diff
    set ft=diff
endfunction

And in .hgrc I've added option: editor = vim "+HgCiDiff()"

It kind of works, but I would like that splited window would be in right side (now it opens up in left) and mercurial message would be focused window. Also :wq could be setted as temporary shortcut to :wq<CR>:q! (having an assumption that mercurial message is is focused).

Any suggestions to make this a bit more useful and less chunky?

UPDATE: I found vim split guide so changing vnew with rightbelow vnew opens up diff on the right side.

© Stack Overflow or respective owner

Related posts about vim

Related posts about mercurial