everyone I'm trying to achieve a behaviour described here Fundamentals of multiple-cursors.

Particulraly the following comment:

Edit several places simultaneously. Either mark several instances of a string like before, but cancel the selection (but not the cursors) immediately using C-g

The only problem is that there is not detailed explanation or description of the commands to achieve that.

Can someone please give an example on can I accomplish that? Thanks in advance!


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:

  1. Select the first instance of var1
  2. Mark the next instance of var1 with mc/mark-next-like-this, which I have bound to C->. Repeat until all the var1 are marked
  3. Alternatively, you could use mc/mark-all-like-this, which I have bound to C-c C-<, to mark all instances of var1 at once.
  4. Press C-g. This cancels the selection of var1, but leaves a cursor at the beginning of each one.
  5. type my, which will then be inserted in front of each instance of var1.
  6. type <enter> when you're done

Obviously you can mix and match this in all kinds of ways, once you get the hang of it.

  • Thank your for your answer. Just a clarification what if your code is like this: var1 = 17 new_var = myvar + 34 function(input) Let's say I want to edit and var1, myvar and input how can I achieve that? Many thanks! – Kirk Walla Aug 25 '18 at 21:00
  • I don't know of a way to mark multiple things that aren't either the same text (eg, "var1"), or at the same column in consecutive lines. ie, you can put a cursor at the beginnings of a bunch of lines, the end of a bunch of lines, or at column 5 of a bunch of lines. It's may be possible, but the normal workflow is designed around modifying multiple instances of the same name, or adding text to the beginning or end of a bunch of lines. – Tyler Aug 26 '18 at 1:20
  • 1
    @Tyler There is the command mc/add-cursor-on-click which you can bind to a mouse button (with modifiers, say). There is also the ace-mc package that uses ace-jump style selection of multiple cursor locations. – Omar Aug 28 '18 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.