evil icon indicating copy to clipboard operation
evil copied to clipboard

Use flush-lines and keep-lines for g//d and v//d if possible

Open geza-herman opened this issue 5 years ago • 2 comments

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.

geza-herman avatar Jul 17 '20 10:07 geza-herman

Agree with this proposition. I just tried g//d on a 15Mb file and it took 4min while flush-lines took 1.2s

Qwarctick avatar May 12 '22 08:05 Qwarctick

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 avatar May 12 '22 08:05 geza-herman

@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.

tomdl89 avatar Nov 01 '22 20:11 tomdl89

Thank you!

geza-herman avatar Nov 02 '22 10:11 geza-herman