[pasted from vim_use]
* Tim Chase [2011.04.28 14:00]:
> Not sure if this is an old-version-of-vim thing, or if it's just a
> peculiar interaction. Scenario: I had a bunch of vim-windows open on
> various files and wanted to close those that contained a given
> pattern (in the example below, using "@" as my pattern to close
> windows with email addresses in them), so I issued:
>
> :windo g/pattern/q
>
> which did as I expected, but had the odd side effect of printing
> misleading messages about additional/fewer lines:
>
> 193 more lines
> E486: Pattern not found: @
> 86 fewer lines
> 16 fewer lines
> E486: Pattern not found: @
>
> (the E486 is ignorable because those were the files that didn't match
> the pattern). No lines were actually added/removed. The
> "more"/"fewer" lines likely comes from Vim noting the number of lines
> before the ":g" and comparing it to number of lines after the ":g",
> and reporting the difference, but not noticing that the
> file/buffer/window had changed in the process.
>
> Looks like a minor bug or underdocumentation to me, though certainly
> not grievous.
Attached is a small patch that fixes this. The problem is that :g
doesn't check whether the buffer it's in after it finishes is the same
as the buffer it started in.
--
JR
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 74503f6ee649 src/ex_cmds.c
--- a/src/ex_cmds.c Sat Apr 02 15:12:50 2011 +0200
+++ b/src/ex_cmds.c Thu Apr 28 22:08:24 2011 -0400
@@ -5369,6 +5369,9 @@
/* When the command writes a message, don't overwrite the command. */
msg_didout = TRUE;
+ /* Remember from which buffer we started the command. */
+ buf_T *initialbuf = curbuf;
+
sub_nsubs = 0;
sub_nlines = 0;
global_need_beginline = FALSE;
@@ -5401,8 +5404,10 @@
msg_didout = FALSE;
/* If substitutes done, report number of substitutes, otherwise report
- * number of extra or deleted lines. */
- if (!do_sub_msg(FALSE))
+ * number of extra or deleted lines.
+ * Don't report extra or deleted lines in the edge case where the buffer
+ * we are in after execution is different from the buffer we started in. */
+ if (!do_sub_msg(FALSE) && curbuf == initialbuf)
msgmore(curbuf->b_ml.ml_line_count - old_lcount);
}