Needing to fallback to :diffget/:diffput instead of do/dp when dealing with a 3-way diff has always bothered me. I've been having to do that more lately, so the attached patch turns a supplied [count] for do/dp into the [bufspec] for :diffget/:diffput.
Obviously, it's not as expressive as being able to use the full bufspec, but, at least for me, I always know the buffer number, so providing the count is much quicker. Cheers, -- James GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <[email protected]>
commit 268126483efdca5661c554caf79fffd2f72804f6 Author: James McCoy <[email protected]> Date: Tue Oct 28 21:11:09 2014 -0400 Use a [count] for do/dp as the [bufspec] for :diffget/:diffput diff --git a/runtime/doc/diff.txt b/runtime/doc/diff.txt index 0ee5878..80a3855 100644 --- a/runtime/doc/diff.txt +++ b/runtime/doc/diff.txt @@ -266,13 +266,19 @@ that the buffers will be equal within the specified range. See below for [range]. *do* -do Same as ":diffget" without argument or range. The "o" stands - for "obtain" ("dg" can't be used, it could be the start of - "dgg"!). Note: this doesn't work in Visual mode. +do Same as ":diffget" without range. The "o" stands for "obtain" + ("dg" can't be used, it could be the start of "dgg"!). Note: + this doesn't work in Visual mode. + + If you give a [count], it is used as the argument for + ":diffget". *dp* -dp Same as ":diffput" without argument or range. - Note: this doesn't work in Visual mode. +dp Same as ":diffput" without range. Note: this doesn't work in + Visual mode. + + If you give a [count], it is used as the argument for + ":diffput". When no [range] is given, the diff at the cursor position or just above it is diff --git a/src/diff.c b/src/diff.c index d324f99..6763533 100644 --- a/src/diff.c +++ b/src/diff.c @@ -2107,12 +2107,21 @@ diff_infold(wp, lnum) * "dp" and "do" commands. */ void -nv_diffgetput(put) +nv_diffgetput(put, count) int put; + long count; { exarg_T ea; - ea.arg = (char_u *)""; + if (count == 0) + ea.arg = (char_u *)""; + else { + /* "count / 10" is one less than the number of characters used to + * represent the number, so add 1 for the full width and 1 for NUL */ + long len = count / 10 + 2; + ea.arg = (char_u *)alloc(len); + vim_snprintf((char *)ea.arg, len, "%ld", count); + } if (put) ea.cmdidx = CMD_diffput; else @@ -2121,6 +2130,8 @@ nv_diffgetput(put) ea.line1 = curwin->w_cursor.lnum; ea.line2 = curwin->w_cursor.lnum; ex_diffgetput(&ea); + if (count != 0) + vim_free(ea.arg); } /* diff --git a/src/normal.c b/src/normal.c index 0116d05..bd5bacd 100644 --- a/src/normal.c +++ b/src/normal.c @@ -9284,7 +9284,7 @@ nv_put(cap) if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') { clearop(cap->oap); - nv_diffgetput(TRUE); + nv_diffgetput(TRUE, cap->opcount); } else #endif @@ -9407,7 +9407,7 @@ nv_open(cap) if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') { clearop(cap->oap); - nv_diffgetput(FALSE); + nv_diffgetput(FALSE, cap->opcount); } else #endif diff --git a/src/proto/diff.pro b/src/proto/diff.pro index 18c4265..3234fde 100644 --- a/src/proto/diff.pro +++ b/src/proto/diff.pro @@ -18,7 +18,7 @@ int diffopt_changed __ARGS((void)); int diffopt_horizontal __ARGS((void)); int diff_find_change __ARGS((win_T *wp, linenr_T lnum, int *startp, int *endp)); int diff_infold __ARGS((win_T *wp, linenr_T lnum)); -void nv_diffgetput __ARGS((int put)); +void nv_diffgetput __ARGS((int put, long count)); void ex_diffgetput __ARGS((exarg_T *eap)); int diff_mode_buf __ARGS((buf_T *buf)); int diff_move_to __ARGS((int dir, long count));
signature.asc
Description: Digital signature
