Hacker News new | ask | show | jobs
by vageli 1252 days ago
Could you expand on your use case? Are you writing the same thing across multiple lines? I've only gotten tripped up on multiple cursors when I somehow activate them.
3 comments

My main use cases:

- Replacing variable and function names: I have Ctrl+D bound to "Mark Next Occurrence", which creates a multiple cursor and replicates the selection I have on my main cursor to the next following similar thing. Instead of changing a name and then search/replace it afterwards, I selectively mark the next occurrences within the scope I'm in and change them all at once.

- Editing multiple similar expressions: If I want to add a new parameter to a function, I can multi-select `existingParam,` (including the comma) and add the new parameter to multiple occurrences within a scope.

- Ctrl-based multi navigation: I use Ctrl + Arrow Keys to skip words a lot. In combination with multiple cursors, it allows each cursor to skip words individually. This is useful for the previous use case (editing parameters) when each parameter might have a different name (and therefore a different length).

- Several alignment and formatting things: This is hard to explain in text. I use it to align the ` = ` sign in repeated variable assignments, to manage indentation, etc.

I can do most of these things using other tools if needed (I did before multiple cursors). The parameter editing is often a vi "showcase" scenario, which I consider to be much more effective using mc than repeating actions or macros.

I don't place cursors with a mouse, I don't add cursors below or above or any other feature. Just "select the next occurrence" or "select all occurrences".

Author here: This is interesting to me. I usually solve all the multi-cursor usage with a range based search and replace (that it's supported in ecode by selecting the range and Ctr/Cmd + F to search and replace over that range). I would like to see how it's used by other users to have a better idea on how it should behave a multi-cursor feature. If you know how to record a video of you editing in the way you explained it would be awesome to see it. Thanks
I use for things that I could do with find and replace (often requiring regex) but I find it faster/easier to just use multiple cursors. With multiple cursors I can convert a PHP array to JSON or JS very easily or take a list of params and turn it in to an object. I do this often when creating client-side TypeScript interfaces for the data the server is going to spit back at me. Example:

* I just select `public` on my first PHP class property

* Use multiple cursors to select all `public`'s that are before the properties I want (Normally by adding 1 selection at a time since I only want the props, not the public methods)

* Arrow over right 3 times (Now my cursor is right before the property names, after the `$`, this is PHP remember)

* Hold shift + control

* Arrow once more to the right (now the variable names are selected)

* Hit Cmd+c (copy all variable names)

* Open new IMyInterfaceDTO.ts file

* Type `export interface IMyInterfaceDTO { <cursor is here now> }`

* Paste in all my variables between the `{}`

* Select the new-line between each variable (I want a cursor before each variable name)

* Then add in `: string;` after each variable (string is the most common, I then manually change it to number/boolean/etc on the props that need it)

Done, now I have a TypeScript interface that matches my php class that gets turned into JSON.

Here is an example of what I'm talking about: https://cs.joshstrange.com/jlH4BnT3

Yes, I could accomplish the same thing with find and replace using a regex but this lets me see each step of the transformation and react easier. Maybe if I was a regex pro I'd feel differently but this method works really well for me and how my brain works. I know it's a lot of steps but I do it reflexively almost on autopilot verses having to stop and think about a regex.

Awesome, it really helps me to visualize the usefulness of the feature. Thanks for taking the time to explain it.
Oh, I completely forgot about copying and pasting multiple cursors. I'm a hardcore user of that as well.
Sure can do!

Here it is: https://streamable.com/vwj0hs

I did three things there:

1. Replace the prefix of several variables from `$mock` to `$stub`

2. Added a prefix to all properties of the object `$r`, which left the camelCasing missing an uppercase letter, I selected that letter on all properties and used "Transform To Uppercase" action on VSCode to camelCase it properly back again.

3. Aligned some keys of two arrays. I selected them, placed some minimal spacing, then hit `Home` to align the cursors to indentation, then used `Ctrl+Delete` to trim the added spaces.

I'll try the range based search, I never used something like that and might like it.

Thank you very much! Indeed it looks really useful. I hope I can implement it soon.
This is also how I go about it in Doom Emacs. I guess either way solves the same problem, just differently.
I cant speak for the commenter you replied to, but I find it great to transform data without any tooling.

As an example, if I have some tabular data, I can quickly turn it into JSON. Find-replace can also add a cursor to each result which is very helpful. Many other code/data transformation tasks are also made trivial with multiple cursors.

Also not author of original comment, but I use it for “stupid data transforms” all the time. Like formatting some stuff for a spreadsheet. I find it faster than writing a script most of the time