views:

1166

answers:

8

Background: JEdit (and some other text editors as well) support a feature called Multiple simultaneous text insertion points. (at least that's what I'm calling it here).

To understand what this means, take a look at the link.

Out of all the features in use in modern text editors, initial research seems to indicate that this is one feature that both Emacs and Vim do not actually support. If correct, this would be pretty exceptional since it's quite difficult to find a text editor feature that has not made its way into at least one of these two old-school editors.

Question: Has anyone ever seen or implemented this feature in either Emacs, Vim, or both? If so, please point me to a link, script, reference or summary that explains the details.

Update: In response to the down-votes, please note I didn't ask whether the feature was "needed". I asked a simple yes/no question, whether it was implemented. I didn't invent the feature. I'm just researching it. I don't give a rats ~~~ who does or doesn't like it.

If you know an alternate way to do the same (or similar) thing, that's fine, but please try to save the soap-boxing and advocacy for people who seek out that kind of fluffy subjective response on SO. If you can't answer an objective question without putting on your editor-religious-warrior costume, please kindly refrain from responding.

+5  A: 

The vim way to do this is the . command which repeats the last change. So, for instance, if I change a pointer to a reference and I have a bunch of obj->func that I want to change to obj.func then I search for obj->, do 2cw to change the obj-> to obj., then do n.n.n. until all the instances are changed.

Perhaps not a flexible as what you're talking about, but it works frequently and is very intuitive and fast when it does.

David Norman
I was going to suggest the . command too. It's an amazingly powerful feature!
PEZ
+2  A: 

I don't think this feature has a direct analogue in either Emacs or Vim, which is not to say that everything achievable with this feature is not possible in some fashion with the two 'old-school' editors. And like most things Emacs and Vim, power-users would probably be able to achieve such a task exceedingly quickly, even if mere mortals like myself could spend five minutes figuring out the correct grep search and replace with appropriate back-references, for example.

Andy
+4  A: 

In EMACS, you could/would do it with M-x find-grep and a macro. If you really insist that it be fully automatic, then you'd include the find-next in the macro.

But honestly, this strikes me as a sort of Microsoft-feature: yes, it adds to the feature list, but why bother? And would you remember it existed in six months, when you want to use it again?

Charlie Martin
+4  A: 

moccur-edit.el almost does what you want. All the locations matching the regexp are displayed, and the editing the matches makes changes in the corresponding source. However, the editing is done on a single instance of the occurrence.

I imagine it'd be straight forward to extend it to allow you to edit them all simultaneously (at least in the simple case).

There is a demo of it found here.

Turns out, the newest versions of moccur-edit don't apply changes in real-time - you must apply the changes. The changes are also now undoable (nice win).

Trey Jackson
A: 

This looks like Regular Expression Search/Replace for Dummies. The trouble starts when the drooling specimen does not realize that the generalization proposed by the computer is wrong. And and the trouble gets worse when the alternative generalization selected by said specimen produces a disaster in the 1200th editing region which is way off screen.

That being said - no, there is no support in Emacs as far as I know.

Arkadiy
A: 

It should be something like this in vim:

%s/paint.\((.*),/\1.paint(/

Or something like that, I am really bad at "mock" regular expressions.

The idea is substitute the pattern:

/paint(object,/

with

/object.paint(/

So, yes, it is "supported"

OscarRyz
+1  A: 

YASnippet package for Emacs uses it. See 2:13 and 2:44 in the screencast.

J.F. Sebastian
A: 

Nope. This would be quite difficult to do with a primarily console-based UI.

That said, there is similar features in vim (and emacs, although I've not used it nearly as much) - search and replace, as people have said, and more similarly, column insert mode: http://pivotallabs.com/users/brian/blog/articles/350-column-edit-mode-in-vi

dbr