Multiple cursors for Emacs. This is some pretty crazy functionality, so yes, there are kinks. Don't be afraid tho, I've been using it since 2011 with great success and much merriment.
Start out with:
Then you have to set up your keybindings - multiple-cursors doesn't presume to know how you'd like them laid out. Here are some examples:
When you have an active region that spans multiple lines, the following will add a cursor to each line:
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
When you want to add multiple cursors not based on continuous lines, but based on keywords in the buffer, use:
(global-set-key (kbd "C->") 'mc/mark-next-like-this) (global-set-key (kbd "C-<") 'mc/mark-previous-like-this) (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
First mark the word, then add more cursors.
To get out of multiple-cursors-mode, press
C-g. The latter will
first disable multiple regions before disabling multiple cursors. If you want to
insert a newline in multiple-cursors-mode, use
Mark one more occurrence
mc/mark-next-like-this: Adds a cursor and region at the next part of the buffer forwards that matches the current region.
mc/mark-next-like-thisbut only for whole words.
mc/mark-next-like-thisbut only for whole symbols.
mc/mark-previous-like-this: Adds a cursor and region at the next part of the buffer backwards that matches the current region.
mc/mark-previous-like-thisbut only for whole words.
mc/mark-previous-like-thisbut only for whole symbols.
mc/mark-more-like-this-extended: Use arrow keys to quickly mark/skip next/previous occurances.
Mark many occurrences
mc/mark-all-like-this: Marks all parts of the buffer that matches the current region.
mc/mark-all-like-thisbut only for whole words.
mc/mark-all-like-thisbut only for whole symbols.
mc/mark-all-in-region: Prompts for a string to match in the region, adding cursors to all of them.
mc/mark-all-like-this-in-defun: Marks all parts of the current defun that matches the current region.
mc/mark-all-like-this-in-defunbut only for whole words.
mc/mark-all-like-this-in-defunbut only for whole symbols.
mc/mark-all-like-this-dwim: Tries to be smart about marking everything you want. Can be pressed multiple times.
set-rectangular-region-anchor: Think of this one as
set-markexcept you're marking a rectangular region.
mc/mark-sgml-tag-pair: Mark the current opening and closing tag.
Tips and tricks
To get out of multiple-cursors-mode, press
C-g. The latter will first disable multiple regions before disabling multiple cursors. If you want to insert a newline in multiple-cursors-mode, use
Sometimes you end up with cursors outside of your view. You can scroll the screen to center on each cursor with
mc/mark-next-like-thiswith no region selected. It will just add a cursor on the next line.
mc/mark-all-like-this-dwimon a tagname in html-mode.
Notice that the number of cursors active can be seen in the modeline.
If you would like to keep the global bindings clean, and get custom keybindings when the region is active, you can try region-bindings-mode.
BTW, I highly recommend adding
mc/mark-next-like-this to a key binding that's
right next to the key for
Multiple-cursors uses two lists of commands to know what to do: the run-once list and the run-for-all list. It comes with a set of defaults, but it would be beyond silly to try and include all the known Emacs commands.
So that's why multiple-cursors occasionally asks what to do about a command. It will
then remember your choice by saving it in
~/.emacs.d/.mc-lists.el. You can change
the location with:
(setq mc/list-file "/my/preferred/file")
- isearch-forward and isearch-backward aren't supported with multiple cursors. You should feel free to add a simplified version that can work with it.
- Commands run with
M-xwon't be repeated for all cursors.
- All key bindings that refer to lambdas are always run for all cursors. If you need to limit it, you will have to give it a name.
- Redo might screw with your cursors. Undo works very well.
Yes, please do. There's a suite of tests, so remember to add tests for your specific feature, or I might break it later.
You'll find the repo at:
To fetch the test dependencies:
$ cd /path/to/multiple-cursors $ git submodule update --init
Run the tests with:
$ ./util/ecukes/ecukes --graphical
- Takafumi Arakaki made .mc-lists.el diff friendly
- Marco Baringer contributed looping to mc/cycle and adding cursors without region for mark-more.
- Ivan Andrus added showing number of cursors in mode-line
- Fuco added the first version of
Copyright (C) 2012 Magnar Sveen
Author: Magnar Sveen firstname.lastname@example.org Keywords: editing cursors
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.