Which editors out of Emacs, Vim and JEdit support multiple simultaneous text insertion points?

送分小仙女□ 提交于 2019-12-03 09:45:35

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.

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).

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?

For emacs, multiple-cursors does exactly that.

Have a look at emacsrocks episode 13, by the author of the module.

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.

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

Another slight similarity: In Emacs, the rectangle editing features provided by cua-selection-mode (or cua-mode) automatically gives you multiple insertion points down the left or right edge of the marked rectangle, so that you can type a common prefix or suffix to all of those lines.

e.g.:
M-x cua-selection-mode RET (enable the global minor mode, if you don't already use this or cua-mode)
C-RET down down down (marks a 1x3 character rectangle)
type prefix here
C-RET (unmark the rectangle to return to normal editing)

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"

It seemed simple to do a basic version of this in Emacs lisp. This is for when you just want two places to insert text in parallel:

(defun cjw-multi-insert (text)
  "insert text at both point and mark"
  (interactive "sText:")
  (insert-before-markers text)
  (save-excursion
    (exchange-point-and-mark)
    (insert-before-markers text)))

When you run it, it prompts for text and inserts it at both point (current position) and mark. You can set the mark with C-SPC. This could be easily extended for N different positions. A function like set-insert-point would record current position (stored as an Emacs marker) into a list and then when you run the multi-insert command, it just iterates through the list adding text at each.

I'm not sure about what would a simple way to handle a more general "multi-editing" feature.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!