I use Windows 7 64-bit. I have compiled gvim 64-bit using ming. The issue occurs on gvim 64-bit, 32-bit and, to a lesser extent, on MacVim.
On Windows, it takes several minutes to carry out the operation. During this time, Windows becomes unusable, which is poor but that's another issue.
On OS X, in MacVim, the same operation takes 30 seconds. With clipboard="", it takes two seconds.
Here are the steps to reproduce the issue:
1. Open gvim with no plugins and no vimrc.
2. :set clipboard=unnamed
3. Open a text file with about 200,000 lines.
4. Enter :g/string/d The "string" should match about 150,000 lines i.e. you want to delete lots of rows!
5. Go for a coffee break (Windows!) or wait 30 seconds (OS X)
In practice, if I issue the command on Windows, I kill the process then open the file again, this time setting clipboard="" before I issue the command.
The workaround (:set clipboard="") is fine if you remember it! It would be nice if gvim did this e.g. (pseudo-code):
old_clipboard = clipboard
try
clipboard = ""
execute global command
finally
clipboard = old_clipboard
end
One consideration for side effects: currently, if clipboard=unnamed, the only text that ends up on the system clipboard is the final deleted line, not all deleted lines. If anything, you might want all deleted text to be on the clipboard but that is not what currently happens. I suspect neither the last line nor all lines is generally required. I don't care (others might) what ends up on the clipboard and would be happy if there was no speed penalty when the command was issued!
It would be great if someone could look at this!
Thanks
Praful
I completely forgot about the black hole register! Isn't vim wonderful just to have that concept!
Thank you ZyX - and John for making sure I didn't miss the black hole advice.
Praful
Thanks Christian - and apologies to all for not seeing the todo list
>
> Here is an experimental patch, that resets the clipboard option for :g
>
> command, when there are many matches (>100). Note: I haven't tested it.
>
I may try the patch or probably wait until it enters the main code base. :g/test/d_ has already entered my muscle memory - probably because the alternative is so disruptive!
Praful
OK - I've tried the patch and can confirm it works.
I'm unfamiliar with what happens once I've applied a patch. Will I need to apply the patch every time I pull/update? Or will I not receive updates to my patched files?
Also, how does this patch become accepted in the official code base?
Thanks
Praful
> I wonder if this only applies to the :g command. Doesn't :%s have the
>
> same problem? And perhaps joining many lines. Anything that repeatedly
>
> puts text in the " register.
I just tried :%s where I substituted something on almost all 200,000 lines of a file. It did the substitutions in less than a few seconds. To make sure I wasn't using Christian's patch, I then tried :g/pattern/d and Windows froze!
I tried the :%s on my patched gvim as well and that worked fine too.
Praful
I should have added that joining many lines (eg 190000J) is fine too. (Clipboard was set to unnamed.)
Praful
I'm not sure how to test the :bufdo, :windo, etc but I'm happy to test the issue I originally reported once a patch has been finalised.
If someone posts the use cases for :bufdo, etc, I'll test those as well
Praful
Are you considering another patch to incorporate Bram's comments? Or is this patch the candidate for inclusion in the Vim code base? If it is, I'll test it.
Thanks
Praful
I have tried this patch and it made no difference! It's still slow when I try g!/<pattern>/d. Using d_ was fine as expected.
This is Windows 7 x64.
Praful
Thanks for the quick response, Christian. Sorry, same again. I still have issue.
Praful
Sorry, still slow! Is there any debugging information I can provide to help you diagnose what's going on?
In case you've forgotten, your original solution did work even though it wasn't as generic as Bram wanted. It could be there is no generic solution and you have to settle for a specific solution.
Thanks
Praful
>
> Hi Christian
>
>
>
> Excellent news: it is now working! I can confirm that the item that remains on the clipboard after issuing g/<pattern/d is the last row that was deleted.
>
>
>
> Thank you for persevering with this issue!
>
>
>
> Praful
I've lost track of this issue. Given that it's fixed, when will this be included in the official patches? When I now patch vim, I have to undo Christian's patch then apply the official patches then redo Christian's patch.
Thanks
Praful
Hmm. I wonder what's going on in mine then? In my config:
https://gist.github.com/dmd/70aaef4072c7e8d78018cef5ecc28903
with a 200000 line file, v/mystring/d takes about 8 minutes with set clipboard=unnamed, or less than a second without.
Is there something I can do to debug why this is happening?
Daniel
I am getting the same result in 7.4.396:
https://gist.github.com/a2c22023308cbc80f88efb3cf22ccb00
Slow with set clipboard=unnamed, fast without.
The only thing in .vimrc is set clipboard=unnamed. Removing that makes it fast.
Now what?
Daniel
Unsetting DISPLAY fixes this for me, if that's a clue.
Daniel
(But, of course, then the clipboard doesn't actually WORK, so that's not really a fix.)
Daniel
This is what it's spending its time doing:
0.000018 poll([{fd=3, events=POLLIN}], 1, 0) = 0 (Timeout)
0.000018 select(4, [0 3], NULL, [0], {0, 0}) = 0 (Timeout)
0.000052 recvmsg(3, 0x7fff09efec00, 0) = -1 EAGAIN (Resource temporarily unavailable)
0.000018 recvmsg(3, 0x7fff09efec00, 0) = -1 EAGAIN (Resource temporarily unavailable)
over and over, thousands upon thousands of times.
Daniel