12 ms·
This exists in most editors I've used (intellij is alt + shift + click or double tap alt, if I recall). I don't know how people program without this feature - t
by staticassertion 9y ago
This exists in most editors I've used (intellij is alt + shift + click or double tap alt, if I recall). I don't know how people program without this feature - they should teach this shit in school.
Multicursor is amazing.
One thing it's been great for:
I have code like:
byte b1 = array[0];
And I want to do this for 16 bytes. Control + D to duplicate 15x. Double tap control, hit up 15 times - now there's a cursor at every row. Hold control, hit right (jump by word), index to end of 'b1' on each line. Ctrl + shift + a, 'increment duplicates' - now every line is 1, 2, 3, 4... 16. `ctrl + right` my way to the index key and do the same thing.
It's awesome.
edit: I just found 'duplicate and increment' :o
- tmerr 9y agoAnd here I am using for loops like a caveman
- alexeldeib 9y agoI think loop unrolling is super cool. We're typically trained in programming to try to eliminate the kind of reuse that unrolling typically looks like, but when applied properly it can work really well. I guess that applies to most tools, though.
- tzahola 9y agoCan you give us an example where manual loop unrolling would be desired over a for loop?
- andrepd 9y agoLanguages/compilers that don't do loop-unrolling automatically. If they do, then yes, it's probably best to let the compiler do it.
- monkpit 9y agoLike which?
- staticassertion 9y agoAll of the languages I can think of rely on the compiler backend for loop unrolling, which means it isn't a guarantee. You might want this if you need to guarantee the unroll. But I wasn't doing this for a loop unroll. I had a fixed size array that I wanted to serialize/ deserialize to/ from capnproto - there are no fixed size arrays in capnproto, so I wrote a message that just had b1, b2, b3... b16, and then some code to pull it out into a statically sized array. It allowed me to pull a bunch of bytes into a much larger statically allocated array without any allocation or bounds checking.
- alexeldeib 8y agoWhat actually brought it to mind was a hardware class where we were instantiating a bunch of the same module but didn't have a programmatic way to do it with our tooling. So...sorta like loop unrolling :)
- Groxx 9y agoYea, I have the mac bindings, and for me it's opt-click to add a cursor, and ctrl-g to select next duplicate of whatever I select. You can even do stuff like "move left 1 word" or "move to begin/end of line" and all cursors follow the same behavior, possibly with different movement-distances. Utterly trivial refactorings in any language (including english), and always feels far easier to understand / predict than Vim's record-and-replay (as useful as it is), especially since you can see the results in every instance as you type. I've been using it in editors since well before VSCode existed. It's very nearly a requirement for me to use an editor now.
- solipsism 9y agoI don't know how people program without this feature You must do some kind of programming I've not encountered in my many years. While my editor of choice can do this, I would have no idea how, because a feature like "increment duplicates" is needed so infrequently that I would never remember the shortcut.
- derimagia 9y agoIt's one of those things that is incredibly useful. Of course it's possible to survive without it, but it's like saying "I don't know how people program without Copy and Paste". It helps.
- khedoros1 9y agoCopy and paste is something that I use many times a day, even when I'm not programming. Needing to do the same edits over multiple lines doesn't happen often in my code. There are appropriate plugins available for my editor, but I've never felt the need to install them.
- staticassertion 9y agoI don't use this as much as copy/paste, but I absolutely use it daily.
- monkpit 9y agoThat quote was referring to column editing mode, not “increment duplicates” shortcut.
- staticassertion 9y agoIncrement duplicates is just one of many, many utilities that pairs well with multiple carets. Formatting is another. Boilerplate code, for example today I had to implemented code like this: impl Into<Node> for ProcessNode { fn into(self) -> Node { Node {some_boilerplate(self)} } } I had 6 node types. Using multiple cursors I: * Implemented it once * Duplicated it 5x * Copied the names of the types I needed to impl for * Attached a cursor to each impl * Used ctrl + left/ right to word-jump, and past in the appropriate area Now it's not like this saved me more than a minute or two, but this sort of thing is extremely common in my experience, across languages.
- billfruit 9y agoI haven't tried this feature on VS Code, but isn't the record and replay macros feature in Emacs(normally bound to F3 and F4) a simpler(and more general, since seemingly it can record arbitrary text transformations) approach to achieve a similar effect?
- SiVal 9y agoWhere did you find "duplicate and increment"?
- staticassertion 9y agoIt might be a plugin called String Manipulation.
- philsnow 9y agoI end up doing everything like that in emacs keyboard macros. For your example, this is the kmacro I ended up with: ;; Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel. ;; Original keys: 2*M-f M-DEL b C-x C-k TAB C-a 2*C-k 2*C-y C-p Command: last-kbd-macro Key: none Macro: 2*M-f ;; forward-word M-DEL ;; backward-kill-word b ;; self-insert-command C-x C-k TAB ;; kmacro-insert-counter C-a ;; move-beginning-of-line 2*C-k ;; kill-line 2*C-y ;; yank C-p ;; previous-line (after you've created a macro, you can get the above by doing M-x kmacro-edit-macro.)
- kazinator 9y agoIn Vim: just write the first line. Then iterate on this key sequence: YP<Ctrl-A>l<Ctrl-A> That can be recorded into a register (say "a") with qaYP<Ctrl-A>l<Ctrl-A>q then replayed with @a, and further repeated with @@. This is nothing new; I was doing this in Vim 20 years ago.
- staticassertion 9y agoI'm sure it's not new.