0

When editing Git commits in Vim, I'd like to automatically split the window on open so that I can edit the commit message in the top pane while keeping the commit change list in the bottom panel.

I have the ftplugin with a gitcommit.vim file for setting some other Git-commit-specific options, but when I add split to it, I get 3 panes (presumably because the second pane also splits, and then something prevents further recursion into infinity?).

I'd also like it to switch to the second panel and move the line that says # Changes to be committed: to the top of the buffer for when I am doing commit-amends and the message is already long. Then, I'd like it to move back to the top buffer. I know what to type to do that, but I'd like it to happen automatically, if possible.

Inductiveload
  • 6,094
  • 4
  • 29
  • 55
  • 3
    Did you check [fugitive plugin?](https://github.com/tpope/vim-fugitive) – mMontu Oct 06 '14 at 15:44
  • Am I understanding this correctly? You want to split the commit window (`s`), go to the new split via `j` then do a search `/^# Changes`, scroll that line to the top (`zt`), and then switch back to the top split `k`? – Peter Rincker Oct 06 '14 at 15:51
  • @PeterRincker: Yes, but how do I send those commands from the ftplugin .vim configuration for Git commits? – Inductiveload Oct 06 '14 at 15:53
  • 1
    Although this does not answer the question: you might want to try [rhysd/committia.vim](https://github.com/rhysd/committia.vim) too. – Yosh Oct 07 '14 at 07:15

1 Answers1

1

Here is a command to put in your ~/.vim/ftplugin/gitcommit.vim file:

command! -buffer -nargs=0 Changes :execute "normal! \<c-w>s\<c-w>jgg"<bar>call search('^# Changes')<bar>execute "normal! zt\<c-w>p"

This provides :Changes command which does what you want. I hesitate to have it fire off immediately as for most commits I doubt you will need this functionality.

I also agree with @mMontu that you should check out Fugitive as well as this Vimcasts post: The Fugitive Series - a retrospective.

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101