Short Answer
Just use the normal interactive buttons. In (regular) vim, pressing p drops you into the interactive terminal patch, so it's the interface you're used to.
For neovim users: Just enter insert mode (i), then it works as a terminal, the cursor goes to 'stage this hunk...' line.
In newer versions, you can use P instead, and the interface is builtin (not an external terminal).
Long Answer: Don't use p
!
If you're already using plugin-fugitive, I'd highly recommend learning how to use it properly powerfully.
From the :Git
window, you can trigger a number of commands.
Pro tip: ) moves to the next file in the window (and ( previous). g?
brings up a list of other shortcuts.
Another answer covers recent updates to the status window that may be even easier to use for patch-like adding than the diff method below, using -
and =
. This is my preferred method.
You can hit dd on any file to bring up a :Gdiffsplit
window. This window will show you the differences between the file on disk and the file in the git index. You add pieces to the git index (simulating git add --patch
), but in a much more "vim-like" way.
Pro tip: in any vimdiff window (including :Gdiffsplit
), use ]c
and [c
to jump between diffs
The working copy is always on the right, and the version in the index is always on the left. Note that updating the index ('patching' pieces of the file) is as simple as pulling changes from the working copy to the index. We have the commands do
and dp
for this. Which to run depends on where you are.
do
(or 'diff-obtain'--:diffget
) pulls the nearby diff over from the other side
dp
(or 'diff-put'--:diffput
) puts the nearby diff in the other side
The result? From the working copy, use dp
to add changes you want to stage, or do
to reset changes. (You can actually also run these from the index, but it's slightly less intuitive to me.)
:diffget
and :diffput
work with ranges (read: visual mode), if you don't want to stage an entire diff hunk at once.
Tip: if the colors look weird, try :diffupdate
I added changes to the index, now what?
Write the index file (e.g. :w
) and watch the status window update!
References