How can I commit files currently displayed in Vim with fugitive?

katatagan picture katatagan · Dec 7, 2014 · Viewed 9k times · Source

I am editing files opened split into three windows. I want to commit those into the repository. Is there any commands to do that?

Answer

Peter Rincker picture Peter Rincker · Dec 7, 2014

There are a few ways to accomplish this task. I will outline the most interactive method which uses :Gstatus.

  • Open up the status window via :Gstatus
  • Move between files via <c-n>/<c-p>
  • Stage/unstage files via -
  • Start committing via cc whilst in the status window
  • Create commit message and save and close window. (I prefer :x)
  • You can also use zj and zk to move between sections
  • Using - on a section will stage/unstage all the files in that section

For more help with :Gstatus see :h :Gstatus or g? when in the :Gstatus buffer.

Can use :Gwrite and :windo to skip the :Gstatus window to make this a bit faster.

:windo Gw
:Gcommit

You can also skip the whole commit window by using the -m flag. e.g. :Gcommit -m "A short message"

I recommend Vimcasts videos on Fugitive: The Fugitive Series - a retrospective

To learn more see:

:h fugitive
:h :Gstatus
:h :Gw
:h :Gcommit
:h :windo
:h :x