Macros and global replace already do what you want.
I've heard the "macros is the same" sentiment many times, and usually it's from people who have never had much experience with multiple cursors, at least not in the situations where it's useful, and therefore don't realize how much more convenient they are in many every-day situations.
In fact, many of the people arguing against multi-cursors have been convinced after trying them that they are better.
Please, read my linked comment for an all-too-common situation.
The basic problem with macros and global replace is that they don't happen immediately and don't give you feedback. I don't know any vim user who hasn't had the distinct pleasure of needing 3 tries to record a macro before they got it right.
What's more, if I record a macro and run it, then realize after it that I want to do a small addition, I have to go through all the "setup" steps again - go back to the start, re-record, add the logical of finding the next block, and so on. I can't just visually see the situation and say "oh yeah, why don't I add this little tweak".
Seriously, take a very common example: having 3 if's one after the other, where you want to add a line at the start of each if block. Doing this with multiple cursors is a breeze - 3 buttons and you get 3 cursors, then write your code. And if, after writing it, you realize you actually want to add another line, you just keep typing. It's literally the same as typing.
Anyway, I've rambled enough on this topic many times. Please, just give them a try - I care a lot about text editors, I love this field, and I honestly think multiple cursors is the best innovation to happen in text editing in many years. And yet it's so often overlooked.
Fact by who?
>The basic problem with macros and global replace is that they don't happen immediately and don't give you feedback. I don't know any vim user who hasn't had the distinct pleasure of needing 3 tries to record a macro before they got it right.
True about macros, which are a very powerful tool that's way more than just multiple cursors. For global replace, however, this is false. Vim has an option to enable visual feedback for select/replace commands. I use it every day and it's awesome.
>What's more, if I record a macro and run it, then realize after it that I want to do a small addition, I have to go through all the "setup" steps again - go back to the start, re-record, add the logical of finding the next block, and so on. I can't just visually see the situation and say "oh yeah, why don't I add this little tweak".
What about recording the rest of the macro and running both of them one after the other?
>Seriously, take a very common example: having 3 if's one after the other, where you want to add a line at the start of each if block. Doing this with multiple cursors is a breeze - 3 buttons and you get 3 cursors, then write your code. And if, after writing it, you realize you actually want to add another line, you just keep typing. It's literally the same as typing.
v<linenum>j:s/if/<whatever>if/g oh wait, I wanted to add another line? uv<linenum>j:<up><change regex>
Also as somebody already pointed out, vim already has plugin(s) for multiple cursor support and they work exactly as they should. I'm not arguing against multiple cursors, I'm just saying that they don't really bring anything new.
By me. I've talked to people and they've changed their minds. Sorry, should've made that explicit.
>What about recording the rest of the macro and running both of them one after the other?
Because sometimes you only think of it later.
>Also as somebody already pointed out, vim already has plugin(s) for multiple cursor support and they work exactly as they should. I'm not arguing against multiple cursors, I'm just saying that they don't really bring anything new.
As I mentioned to them, I used that plugin, and while it's awesome and I totally love the author for making it, it just isn't as good. See my other comment for details.
And again, I really disagree that they don't bring anything new. That's like saying that WYSIWYG text editors don't bring everything new over systems like Latex. Can you do everything in both systems? Yes. Is it sometimes easier to just select text and hit "ctrl+b"? Yes. Is it always better? No. But it's good to have both options, as sometimes one crushes the other.
Again, I love vim, and I definitely use some of the very methods you've mentioned. But I'm not here to sell you anything, I don't earn anything by convincing you to at least give multiple cursors a shot, except knowing that if you're dismissing them without having tried them then you're missing out and that makes me sad.
This may only show that you grok VimScript way of thinking, not Vim way of thinking.
You need not re-record a macro, a macro is stored in a register. Just edit the register, and you're good to go with you new, (supposedly) improved macro.
In Vim, you edit in Normal mode, and insert in insert mode. Multiple cursors is a means of moving editing into insert mode, and thus in spite of the Vim way. I am an Emacs user * and there is a multiple-cursors mode for Emacs, which quite useful as Emacs is modeless.
* If we're doing SLOC porn here, I've a ~400 SLOC vimrc with nice gems in it, and is nicely and extensively commented. I've switched to Emacs for my love of Lisp and newfangled dislike of some parts of Unix.
True enough that it doesn't prove anything.
"You need not re-record a macro, a macro is stored in a register. Just edit the register, and you're good to go with you new, (supposedly) improved macro."
I know. And if you think this process is easier, faster, or saves keystrokes over using multiple cursors, then I think you're wrong.
"In Vim, you edit in Normal mode, and insert in insert mode. Multiple cursors is a means of moving editing into insert mode, and thus in spite of the Vim way."
No no no! That's the beauty of using multiple cursors in vim. You can have (potentially) multiple cursors in Normal Mode, and use all the normal vim commands. That's what makes it so sad that it doesn't have multiple cursors, because if you can merge the power of multiple cursors with the power of vim, you get something amazing.
Imagine having the following:
<pre>
<div>some text</div> <div>Some other text</div> <div>Third</div>
</pre>
Then imagine you want to, for some reason, copy-paste the contents of the different divs into (say) another buffer.
With multiple cursors, you can select the three lines, use the vim commands to yank the text object that's in between the divs (yit), and then paste it elsewhere. This is not possible in Sublime Text, since it has no way of saying "select text between divs". Or even, doesn't have vim's "f" command so one could jump to the "<" character opening the second div.
Vim poses a way to edit text; Sublime, Emacs and other modeless editors pose another. One enables neat tricks via a very nuanced and powerful editing language, that is Vim verbs, text objects et cetera, and the rest do not provide such mechanism, in favour of simplicity and ease of use (it is easier to start typing in Emacs than Vim, whereas it is easier to do editing in Vim than Emacs, but only for the knowledgeable user).
Do not get me wrong, I am not thinking multiple-cursor-editing is useless; in fact, I use it quite a lot in Emacs[1], and I like how it indeed helps me do my multi-line editing with instant feedback. My argument is that such editing has little to offer to a user that has spent a month-or-so to master Vim.
this is very doable, lets say you record a macro to 'a'
1. q:
2. let @a='
3. ^r^ra to put in the current contents of the macro
4. edit as you see fit
--- you should now have something like ---
let @a='contents of macro'
5. ???
6. profit<pre> .some-css-rule { padding-left:50px; padding-right:50px; } </pre>
Say I want to edit those two numbers. With multi-cursors, it's as simple as select one number, hitting a button that causes the other number to be selected, then writing the new value.
Now, after I wrote it, I realize I forgot to put a space after the colon, and want to change the formatting. No problem - I just make the change to the first line, and the next line follows.
Same as macros? Kind of. But let's say I make a mistake in the macro, e.g., I move the cursor left to the beggining of the line letter-by-letter instead of hitting "home", which is a killer for a macro since each line is a different length. (this is a contrived example a real vim'er will never do, but there are plenty of real examples of 'oops forgot about that' things when recording macros).
Anyway, when I run my macro, suddenly things won't work, and then undoing and starting the re-record process takes time. But if I'm doing this with mulitple-cursors, I see right away, visually that something's wrong, and it's easy to fix - I just hit "home" after moving the cursor left.
And note - this is a drop-dead-simple use case that happens 10's of times a day for any css programmer. Similarly, most programmers will run into cases where they have two similar if blocks one after another, or two similar "except" blocks, and so on.
And that's not even going into lots of other, very powerful cases, like taking a function that gets a list of paramaters, and being able to easily manipulate these paramaters, e.g. given "foo(a, b, c, d, e)", I can easily multi-cursor all the commas, then copy all the params, then paste them after the func definition, hit enter, and I've got a list of all the params after the function definition. And this isn't hard, at all! I visually see everything I'm doing as I do it, and if something goes wrong, I fix it on the spot.
I could ramble more about this, but I think I've either convinced you I'm crazy, or at least to try multi-cursors out :)
:s/50/60/g
:s/:/: /g
No need to touch the mouse or use macros. Many use-cases for multiple cursors are satisfied by the core functionality of vim, however they may not be immediately obvious.
Take an example like the following:
def foo(): // do stuff
def bar(): // do stuff
Now I want to change my comment to say:
// The function foo does stuff
With multiple cursors, I select both def's, copy the following word, then go down and change the comment.
Again, I'm not saying this can't be done in vim. But it's just plain easier to do with multiple cursors. And if you don't believe me, well, that's your right of course. But having used both, extensively, I'm telling you - please, at least give it a try. For many daily use cases, it's just so much easier. And I don't get anything out of selling you on multiple cursors except for the warm fuzzy feeling of maybe helping a fellow developer learn something that will help them.
.some-css-rule { padding-left:50px; padding-right:50px; margin:50px; }
Pretend you want to avoid changing the margin.or even just /50<CR>r6n.
if there's any new feature I'd like to see in neovim it would be one key that will repeat an ex command like period does for normal/visual mode
:s/50/60/<CR> @:
And that still won't handle .some-css-rule { margin:50px; padding-left:50px; padding-right:50px; }
The second example will work, for this, but not for the situation where you change your mind halfway through and decide you want 70px instead.:s/t:50/t:60/g
More serious response: I think after many years of training ones brain to use the features available to it some of those features become second nature and subconscious. This is great for editing and it's the reason I immediately saw that you left me a really easy way to do it, but it can make seeing the value of new features more difficult.
.some-css-rule { padding-left:50px; padding-right:50px; margin-left:50px; margin-right:50px; }
I run into examples like this a lot and have yet to find an elegant way to deal with it. Honestly, I'd like to see if there's a simple solution.I find that I spend a lot of time in my editor crafting regular expressions to do clever replacements and I've yet to get so good at it that it doesn't distract me from my editing.
Of course, you're still going to run into hundreds of situations where you have semi-duplicate code. That's just how real-world programming works.
Just playing devil's advocate, I've never come across a situation where I wanted multiple cursors that sed or macros couldn't do for me.
(and vim doesn't have multiple cursor support in the sense that I mean it).
One easy limitation comes to mind - you can't copy-paste different cursors, then paste them as unique items. E.g., given a list "a, b, c", I want to be able to multi-cursor the letters, copy them, then paste them into 3 multi-cursors somewhere else. Hard, very hard to implement.
That doesn't sound hard to implement iff you plan for those features from the beginning. I have my own editor hobby project and during my reading I got convinced multiple cursors are great for the reasons you described in your other comment.
I hadn't thought about multi cursor copy/paste so I'm wondering what else I've missed.
I wrote to Thiago about this already, but we don't even need multi-cursor support - just a few additional hooks so we can implement a multi-cursor plugin.
Although to be honest, making it part of core is vastly preferable, since it is a hard feature to get right (e.g., how do you deal with copy-pasting into multiple-cursors)?