Use vimdiff to replace entire file?
I'm using vimdiff for a git merge. Is there a quick way to select 1 file to use, right now i'm just selecting everything from one buffer, replacing the $MERGE with that, and then saving. I guess I can macro that, but was wondering if there is a bett开发者_如何学运维er way. Thanks!
Several ways:
:%diffput
to do 'put' all changes from the current buffer to the 'other' buffer. This makes it easy with three-way diffs:
:%diffput OURS
The 'OURS' pattern will match uniquely on buffernames participating in the current diff
All the above can be done in reverse, substituting do or :diffget
You should take a look at Tim Pope's Fugitive plugin. It's a really usefull plugin.
When you run Gdiff
in a conflicted file, 3 files are opened - target, merged and working copy. You would switch to the file you want to save, and execute Gwrite!
to save that file.
There is a whole Vimcast explaining how to resolve merge conflicts with this plugin(And other 5 vimcasts explaining more about Fugitive.vim).
I think :%diffget LO
or :%diffget RE
is what you need.
Note: you need to run it in the MERGED part of vim windows. You can move cursor around the windows using Ctrl+w;←/↑/→/↓
- Make sure that all participating buffers are in diff mode (see
:h start-vimdiff
on how to start diff mode) - Do
v
for VISUAL MODE in the Base - Select the whole file (press
Page Down
all the way) - Write
:
thendiffget <buffer number/name>
(: ls
will list all buffers, generally in vimdiff they are from right to left 1-3 or 4 if 3 way diff) - Afterwards just
: wqa
and you are done
Alternatively, after step 0., one could do :%diffget <buffer number>
to get all changes from the specified buffer as :diffget
also accepts ranges. (See :%
and :diffget
.)
The reverse would also work: :%diffput <buffer>
will send all changes to buffer number, making the two buffers have the same content.
精彩评论