How do I only dp or do just the lines, not the entire block in Vim diff?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 How Do I Only Dp Or Do Just The Lines, Not The Entire Block In Vim Diff?
01:28 Accepted Answer Score 39
03:01 Answer 2 Score 4
03:54 Answer 3 Score 1
04:12 Thank you
--
Full question
https://superuser.com/questions/404333/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim #macvim #vimdiff
#avk47
ACCEPTED ANSWER
Score 39
There are a number of ways to do this.
- Select the range of lines in the destination buffer that you want to obtain from the source buffer and use
:diffget
. For example, you could visually-select a range of lines withV
, then type:diffget
. - Select the range of lines in the source buffer that you want to put into the destination buffer and use
:diffput
. For example, to put the current line into the other buffer, type:.diffput
. - Use yank and put. Select the range of lines in the source buffer that you want to copy into the destination buffer, yank them using
Y
, move the cursor to the destination buffer and put them where you want them withp
orP
, then delete the lines you don't want. - Yank as above, but in the destination buffer, visually-select the range of lines you want to replace (not necessarily the same number of lines) and type
"0p
. That uses the 0 (zero) register which always contains the text of the most recent yank.
To "refresh" the display to show the proper highlighting, execute :diffupdate
or simply :diffu
. Sometimes that isn't sufficient and you need to move the cursor to the other window to complete the refreshing.
You can read more about copying diffs in
:help copy-diffs
ANSWER 2
Score 4
I also wanted to modify one line at a given moment during a diff. So I created a simple map and put them in my vimrc file.
nnoremap <silent> <leader>dp V:diffput<cr>
nnoremap <silent> <leader>dg V:diffget<cr>
You could use do instead of dg, but I am more used to thinking "diffget" instead of [o]btain.
For your bonus, I just use a another simple map twice:
nnoremap <silent> <leader>df :call DiffToggle()<CR>
Now, df will turn off/on the diffmode, so I just turn it off and back on.
And a bonus option is to add
nmap <silent> <leader>du :wincmd w<cr>:normal u<cr>:wincmd w<cr>
This will allow you to undo a typo or unwanted change on the other file/window, because :undo of just u will only undo a change in the present window.
ANSWER 3
Score 1
An other way is to prepend the diffput
command with the line range you're interested in. So in your example, you would issue the following command in the left hand pane:
:15,16diffput