Use flush-lines and keep-lines for g//d and v//d if possible
Issue type
- Enhancement request
It would be awesome if evil handled some of the global commands specially. I use g//d and v//d a lot. But these are much slower than the emacs built-in flush-lines and keep-lines. Which is not a problem for small files, but for large files the difference matters a lot (for example, a 1 MB file, executing a lot of deletions: 90 sec with v//d, and instantaneous with keep-lines).
I understand that g//d and v//d may be more flexible and powerful than flush-lines and keep-lines. But for simpler cases I think emacs builtins can do the job.
Agree with this proposition. I just tried g//d on a 15Mb file and it took 4min while flush-lines took 1.2s
I created this advice. It's likely that it has some flaws, like how begin and end exactly handled, or maybe some compatibility issue, like the original global command updates some evil state which is not done by this advice. But for my use case it works:
(defun my-evil-ex-global (orig-fun &rest args)
(let ((begin (nth 0 args))
(end (nth 1 args))
(pattern (nth 2 args))
(command (nth 3 args))
(invert (nth 4 args)))
(cond
((and (string= command "d") (not invert))
(flush-lines pattern begin end t))
((and (string= command "d") invert)
(keep-lines pattern begin end t))
(t (apply orig-fun args))))
)
(advice-add 'evil-ex-global :around 'my-evil-ex-global)
@geza-herman @PhilippeNoel1 sorry for the delay - this is now implemented in master. Benefit over above advice is being able to use vim-style regexps including case-(in)sensitivity flags.
Thank you!