Home

Awesome

Build Status MELPA MELPA Stable NonGNU ELPA

multiple-cursors.el

Multiple cursors for Emacs. This is some pretty crazy functionality, so yes, there are kinks. Don't be afraid though, I've been using it since 2011 with great success and much merriment.

Maintenance warning

I use this package every day, and have been doing so for years. It just works. At least, it works for all my use cases. And if it breaks somehow, I fix it.

However, it has become painfully clear to me that I don't have time to fix problems I don't have. It's been years since I could keep pace with the issues and pull requests. Whenever I try, I keep getting feedback that my fix isn't good enough by some standard I don't particularly care about.

So, I have closed the issue tracker and the pull requests. I hope you can happily use this package, just like I do. If it doesn't work for you, then I'm sorry. Thankfully Emacs is infinitely malleable, you can probably fix it yourself.

TLDR: I am still maintaining this package, but I am no longer crowdsourcing a list of issues.

Installation

I highly recommend installing multiple-cursors through package.el.

It's available on MELPA, MELPA Stable and NonGNU ELPA (enabled by default from Emacs 28 onwards):

M-x package-install multiple-cursors

The package depends on the cl-lib package, so if you do not use package.el or have a recent Emacs, you would need to install that too: see GNU ELPA.

Basic usage

Start out with:

(require 'multiple-cursors)

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 <return> or 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 C-j.

Video

You can watch an intro to multiple-cursors at Emacs Rocks.

Command overview

Mark one more occurrence

Juggle around with the current cursors

Mark many occurrences

Special

Tips and tricks

BTW, I highly recommend adding mc/mark-next-like-this to a key binding that's right next to the key for er/expand-region.

Binding mouse events

To override a mouse event, you will likely have to also unbind the down-mouse part of the event. Like this:

(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)

Or you can do like me and find an unused, but less convenient, binding:

(global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)

Unknown commands

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")

NB! Make sure to do so before requiring multiple-cursors.

It is possible to set multiple-cursors to "run-for-all" for every command except for those that are listed in mc/cmds-to-run-once. To enable this set mc/always-run-for-all to non-nil. Add commands to be run once to mc/cmds-to-run-once in ".mc-lists.el".

Known limitations

Contribute

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:

https://github.com/magnars/multiple-cursors.el

To fetch the test dependencies, install cask if you haven't already, then:

$ cd /path/to/multiple-cursors
$ cask

Run the tests with:

$ ./run-tests.sh

Contributors

Thanks!

License

Copyright (C) 2012-2016 Magnar Sveen

Author: Magnar Sveen magnars@gmail.com 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/.