4 ms·
I agree multiple cursors are awesome and largely can replace macros with real-time visible changes. But there is one use-case of macros that cannot be replaced
by Peaker 14y ago
I agree multiple cursors are awesome and largely can replace macros with real-time visible changes.
But there is one use-case of macros that cannot be replaced with multiple cursors -- one where the places being affected by the macro are themselves computed by the macro.
- edanm 14y agoCan you please give an example of that? You've got my curiosity piqued :) Btw, another place this can't be used is across multiple files, at least the way ST does it.
- lloeki 14y agoSample def qux(bar, baz, qux) pass def quuux(grim, gram, grom) pass def quuuuuux(hip, hop, zoom) pass Delete second argument (of 3+ arg functions): /def<CR> # search qd # record as 'd' 2f,dF,n # find second arg q # done recording @d # again (or n to skip) Example intentionally simplified/convoluted. I'm doing stuff like this on the spot routinely, and there's no way multiple cursors could do this because I apply verbs to text objects that ST has (unless I'm missing something) no way of knowing about in a visual paradigm without resorting to guessing what I mean. What would be killer is mixing both, i.e visually selecting where to apply a vim macro.
- Peaker 14y agoIf you put the "/def<CR>" part in the macro too, then you can re-execute it multiple times. I think it's actually useful, not simplified/convoluted..
- edanm 14y agoActually, this is a perfect example of using Multiple Cursors to get the job done more easily. I'd select all three "def"s simultaneously, then move by word three/four times using ctrl+right, or plain old "w" if using ST's vim mode. When I'm on the second param, I'll delete forward to the next ",". I could also just ctrl+right my way until the next word, which would be the same. Just to recap the keys I'd press: /def (select first def) ctrl+d * 2 (select using multi-cursors the next two defs ctrl+right * 4 (to get to the second param) ctrl+shift+right (to select the entire second param) delete And if I mess up at any point, I instantly see it. If I did something that only works for the first case but not the others, I see it immediately. Note: Using vintage mode, Sublime Text has vim shortcuts. Without it, Multiple Cursors still rock, but are missing a LOT of their power (exactly because of situations like this). In fact, in Sublime Text 1, for which vim mode didn't exist, I actually implemented a plugin to emulate the "f" and "t" movements because they were so good.
- Peaker 14y agoHow do you make multiple cursors that are at the exact locations you need? That's something that a macro is useful for. His macro is less useful because for some reason he did his search outside of the macro. Maybe the search is not for "def", but for "def prefix", so ctrl+d is not applicable to form the multiple cursors. It could be nice if you could record your movements to form the "next" cursor and immediately see all future generated cursors given that movement (similarly to the "recursive draw" web app). Then you could perhaps truncate the infinite list of cursors at some finite point somehow, and then operate your multiple cursor operations.
- edanm 14y ago"How do you make multiple cursors that are at the exact locations you need?" There are a few simple tricks. In this case, I hit "ctrl-d", which does the following: 1. If nothing is selected, it will select the word the cursor is on. 2. If something is selected, it will select the next match of this word, using another cursor. In other words, I'll put my cursor on "def", hit ctrl-d, and "def" will be selected. Hit ctrl-d again, and the next "def" will be selected. Etc. Technically, in Sublime Text, every search makes a multiple cursor. I could hit alt-f3 (IIRC) to select all matches of "def", and they'd all be multi-selected. But like I said, in this case it's really easy. There are more advanced tricks - what if the word "def" appears inside the text? Well, you can select not only the def, but also the whitespace before the def, and it will selected the next "def" which is at that exact indentation. And like I mentioned in another comment, I even wrote a plugin to make multi-selections more easily, by splitting on a certain character. So that a list like this: (int a, int b, char c) can easily be split into 3 selections, around the comma.