21

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 ...


17

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 ...


10

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 ...


7

Once text has been killed, exit multiple-cursor (enter) and while in new buffer hit C-x r y (normally the killed text is in the rectangle kill-ring)


6

I'd like to add some extras that I sometimes use with multiple-cursors. I've found the following to be useful: iy-go-to-char 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-...


5

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, ...


5

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-...


5

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 ...


5

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 ...


4

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 change. ...


4

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 ...


4

Multiple cursors asks you for unknown commands if they should be run for 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: ...


3

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 ...


3

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 ...


3

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: x_1 x_2 x_3 x_4 x_5 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 ...


3

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 Which means: 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.


3

From future. Now it is (define-key iedit-mode-occurrence-keymap (kbd "RET") 'iedit-mode)


2

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.


2

M-x set-fill-column as desired. M-q: fill-paragraph. M-x align-cols. The code for align-cols is here


2

I also have the same problem, finally I decided to add this package: https://github.com/knu/phi-search-mc.el 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 ;;; Commentary: ;;; my configuration for multiple ...


2

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 () (interactive) (save-excursion (goto-char (point-min)) ;; start at line 2 (forward-line 1) (while (progn (mc/create-fake-cursor-at-point) ...


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.


2

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 ...


2

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") (defun mc/insert-fancy-...


2

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.


1

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 | |-------------+-----------------------------...


1

(require 'evil-mc) (global-evil-mc-mode 1) 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.


1

For example, if I have the following text: var1 = 17 var1 = var1 + 34 function(var1) 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 ...


1

The following code fragment should do what you want: (require 'cl-lib) (setq buffer-undo-list (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)) ...


1

The function you are looking for is mc/mark-next-like-this. If you have no active region, then it will select one (or more) extra lines. Documentation: Find and mark the next part of the buffer matching the currently active region If no region is active add a cursor on the next line With negative ARG, delete the last one instead. With zero ARG, skip ...


Only top voted, non community-wiki answers of a minimum length are eligible