Multiple Cursor editing in Emacs

There is one nice feature I first met in Sublime: multiple cursors. You have a variable name occurs four time in you function, now you want to change the name, how you gonna do? It will be tedious to replace them one by one.

The multiple cursors allow you to set one cursor for each of the occurrences and when you editing all of them changes according to your editing.

This post shows how to the same thing in Emacs.

First install the multiple-cursors package:

Open you ielm buffer and run

 
ELISP> (require 'multiple-cursors)
 
multiple-cursors
 
 

Before you bind keyboard shortcut to the command, let's see what they can do.

The feature I wanted: to change variable name, in Sublime you select the word and press Alt + F3 and start editing. In Emacs you mark the variable and execute M-x mc/mark-all-like-this and start editing, when you finished press Enter to quit multiple cursors.

As illustrated below

Bind to any keyboard shortcut as you wish, but for me the M-x mc/mark-all-like-this is enough. Sometimes the command name is easier to remember than the keyboard shortcut.