Multiple Cursors in Emacs Evil Mode

I recently came across multiple cursors again, and decided to revisit these in Emacs. It's not something that is necessary to utilize Emacs effectively, but there are cases where it is much easier to work with than regex replace.

While searching for multiple cursors and Evil mode, I discovered that the author of DOOM Emacs originally created their own multiple cursors package (evil-multiedit) due to the limitations of the "standard" multiple cursors support in Evil mode. @hlissner's repository also mentions that evil-mc is now mature, so I've decided to move forward with that package.

Installing evil-mc is as follows:

(elpaca evil-mc
  (setup evil-mc
    (:load-after evil-mode)
    (global-evil-mc-mode 1)))

evil-mc is great. Thanks to @gabesoft for maintaining this package. Simple usage is to put the cursor on a word, or highlight some text, and then use g.n or g.N to create cursors at the next match. I usually use g.a to create cursors at all the matches.

Something I didn't like is the requirement to use g.q to exit multiple cursors. I wanted <escape> to get me out of multiple cursors when in normal mode.

Here's how to do that:

(defun +evil-normal-state ()
  "Returns to `evil-normal-state'.
When in insert mode, abort company suggestions and then go to normal mode.
When in normal mode, abort multiple cursors and then go to normal mode.
Always quit highlighting."
  (interactive)
  (if (eq evil-state 'normal)
      (if (fboundp 'evil-mc-undo-all-cursors)
          (evil-mc-undo-all-cursors)))
  (if (eq evil-state 'insert)
      (if (fboundp 'company-abort)
          (company-abort)))
  (evil-ex-nohighlight)
  (evil-normal-state))

(elpaca evil
  (setup evil
    (:general
     (:states '(normal insert)
              "<escape>" #'+evil-normal-state))))

This function also includes some other behaviors I prefer, such as exiting company suggestions and quitting the current search highlighting.

That's it, here's another example of a great package for Emacs, and the infinite customization of Emacs with a little emacs-lisp knowledge.

Related configuration here: https://github.com/donniebreve/dotfiles/blob/master/.emacs.d/init/init-evil.el/