I basically have two frequent use cases for multiple-cursors:
Replace some string. Mark one instance of a string, then use mc/mark-next-like-this and mc/mark-previous-like-this to mark more instances of it. I then immediately hit C-w to delete every instance, and write a new string instead. I use this often to rename a variable in code.
Edit several places ...
In addition to the uses @bastibe describes, I use multiple cursors to add or remove text from the beginning/end of a group of lines:
Move point to the beginning or end of the area of interest
call set-rectangular-region-anchor (bound to whatever key you like, I think the suggestion from Magnars was H-space, if you have a hyper key)
Moved point forward or ...
Yes, it's possible with multiple-cursors.
Let's say you have atleast 5 consecutive empty lines.
With the cursor at the topmost empty line, create 5 multiple cursors by keeping on hitting C-> (default binding for mc/mark-next-like-this).
Type the common variable prefix: x_ as per your example.
Insert numbers starting with the prefix you specify (default ...
I never used iedit extensively, so I could be unaware of some of its
features, but basically iedit is a more interactive search and
replace: you can select occurrences of a string in some scope (region,
defun, buffer, etc.) and then replace them with something else.
Compared to that, multiple-cursors generalizes in two directions, the
second much more ...
I'd like to add some extras that I sometimes use with multiple-cursors.
I've found the following to be useful:
Sometimes, you find yourself needing to move to the next # or the next , or some specific delimiter. This is especially handy when you need to move across different numbers of words for each cursor.
It provides the functions iy-go-...
The first time you run kill-region in multiple cursors mode, it asks Do kill-region for all cursors?. I guess you accidentally replied n to that question - and multiple-cursors-mode remembers this answer forever. You can check this by looking at the value of the variable mc/cmds-to-run-once (that is, type C-h v and the name of the variable).
To fix this, ...
A list of minor modes that do not play well with multiple cursors mode can be set via mc/unsupported-minor-modes.
Any modes added to this list will be disabled when entering multiple cursors mode, they will be re-enabled once you drop out of multiple cursors mode.
You can add an item to this list like so
(add-to-list 'mc/unsupported-minor-modes 'flyspell-...
This is because read-char is advised to have special behaviour. When running in 'multiple-cursors-mode' it caches the character read the first time. If this cache is full then it does not ask for a character again.
Whatever function is called by "c" in the interactive description is not advised in this way.
The implementation is incredibly hackish: for ...
Multiple cursors asks you for unknown commands if they should be run for all cursors or not: "Do org-self-insert-command for all cursors? (y or n)". If you answer this prompt with no it will remember your choice and never ask again. Therefore using that command afterwards is not run for all cursors.
See the unknown commands section in the readme:
You can give multifiles a try. From its README:
Bind a key to mf/mirror-region-in-multifile, let's say C-!. Now mark a part of the buffer and press it. A new multifile buffer pops up. Mark some other part of another file, and press C-! again. This is added to the multifile.
You can now edit the multifile buffer, and watch the original files
The command mc/edit-ends-of-lines adds a cursor to the end of the every line in the region. There are many ways to set the region. If you want to mark every line in a file, you can set the region to the whole file with C-x h.
It's very helpful to spend a few minutes reading the documentation for multiple cursors, which includes a list of all the different ...
In Emacs, the points (cursor) is always on the visible portion of the file you are visiting. This coded deep down in the guts of the program, so you won't be able to change this without a great deal of effort.
As a work around, you can use C-v and M-v to navigate back and forth from one multiple-cursor selection to the next. You can also hide all lines that ...
The following function creates messages only, instead of actually deleting anything. If this approach seems appealing, then (message "No real or fake cursor here: %s" line) can be substituted with (kill-region pbol peol) to kill the line and place it into the kill-ring. If the user wishes to also remove the \n at the end of the line, then use (kill-region ...
This can also easily be done with built-in features of Emacs, namely
keyboard macros. Let's say, as in kashualmodi's answer, that you want
to write this:
You can type: C-1 <f3> x_ <f3> RET C-5 <f4>. Step by step:
C-1 <f3>: the <f3> starts recording a keyboard macro, each
keyboard macro gets its own counter ...
I too love multiple cursors, but for this one I'd use keyboard macros.
F3 C-3 C-n M-^ M-^ M-^ C-n C-0 F4
Start kbd macro.
Move down 3 lines.
Join 3 lines up.
Move to next line.
Finish and repeat kbd macro indefinitely.
You can then proceed to use align-regexp like the other answers explain.
Define a key for the iedit-mode keyboard map, like this:
(define-key iedit-mode-map (kbd "RET") 'iedit-mode)
So, when you start editing a piece of text with iedit-mode, you can turn it off by just pressing RET or any key you like.
I also have the same problem, finally I decided to add this package:
So the complet setup is multiple-cursors, phi-search adn phi-search-mc, and having this file configuration for multiple cursors and phi-search it works well:
;;; file --- my-multiple-cursors.el
;;; my configuration for multiple ...
This function will add a cursor at every even-numbered line. It basically goes to line 2, and starts adding cursors every 2 lines until the end of buffer.
(defun mc/mark-even-lines ()
;; start at line 2
You may have accidentally answered "no" to the question "Do upcase-region for all cursors? (y or n)" at some point in the past, which caused it to be added to C-hv mc/cmds-to-run-once whereas you actually want it to be in C-hv mc/cmds-to-run-for-all.
Type C-j [bound by default to electric-newline-and-maybe-indent], or C-q C-j [just a plain hard return], to insert a hard return when using the multiple-cursors library. The readme.md file contains the following excerpt:
To get out of multiple-cursors-mode, press <return> or C-g.
The latter will first disable multiple regions before disabling ...
The mc/insert-numbers has the increment and number format
hard-coded, but you can use this mc/insert-fancy-numbers command
instead. It'll prompt for start, step and format specifier; for your
example you'd answer 6, 2 and %02d, respectively:
(defvar mc--insert-fancy-numbers-increment 1)
(defvar mc--insert-fancy-numbers-format "%d")
The way I'd do this is with search and replace. You can call Lisp code from a regexp replacement with \,(my-function …). So call M-x replace-regexp (or C-M-% which is bound to query-replace-regexp by default). Use \[guid_here] as the regexp to search for and [\,(upcase (uuid-string))] as the replacement text.
It's in the README:
If you get out of multiple-cursors-mode and yank it will yank only from the kill-ring of main cursor. To yank from the kill-rings of every cursor use yank-rectangle, normally found at C-x r y.
As of Nov 2018, the spacemacs develop branch has a multiple-cursors layer available which notes that:
Currently the only supported backend is evil-mc, but more backends will be available in the future.
The evil-mc package provides the following key bindings:
| Key Binding | Description |
you can look for key bindings of evil-mc, personally I like it quite a lot...
C-n for next matching word under cursor, and most of the suite under "gr"
There is also iedit that works quite well, though I normally stay on evil-mc.
For example, if I have the following text:
var1 = 17
var1 = var1 + 34
Say I want to change the name of my variable from var1 to myvar1. To use the recipe from the linked answer, the steps are:
Select the first instance of var1
Mark the next instance of var1 with mc/mark-next-like-this, which I have bound to C->. Repeat until all the ...
The following code fragment should do what you want:
(cl-remove-if (lambda (x) (and (consp x) (eq (car x) 'apply)
(setq x (cdr x))
(consp x) (memq (car x) '(activate-cursor-for-undo deactivate-cursor-after-undo))
(setq x (cdr x))