4

Is there a way to open multiple buffers that are open at the same time? The idea is to be able to refactor code and variable names in multiple files at once. I know that dired-do-find-regexp-and-replace exists but I was hopeing for a way where I could more clearly see what was happening.

Perhaps something related to multi-occur. Or allowing me to have multiple files open in one buffer and then using multiple-cursors.

Drew
  • 75,699
  • 9
  • 109
  • 225
Jules
  • 1,275
  • 7
  • 12
  • 2
    I recommend using both `wgrep` and `multiple-cursors` -- they changed my life for the better. – lawlist Apr 18 '16 at 18:12
  • 1
    Your comment led me to find that `ivy` can open an "occur" or "mult-occur" buffer and then from there I can use wgrep to edit that buffer! Thank you so much for leading me on the right track – Jules Apr 18 '16 at 18:29
  • 1
    Why do you need/want to visit the multiple files *in the same buffer*? Why not visit them in separate buffers (separate windows or separate frames)? This sounds like an [XY problem](http://meta.stackexchange.com/q/66377/231821) - what is it that you are really trying to do (e.g. with the multiple files)? – Drew Apr 18 '16 at 20:29
  • To edit multiple places, perhaps renaming a variable in multiple files or something of that ilk, without having to repeat that in every buffer I want to change. At the time of writing I had no exact use but it has been something that I've wanted to do in the past and I thought it was an interesting problem – Jules Apr 18 '16 at 21:44
  • Define *"more clearly see what was happening"*. – Drew Nov 27 '18 at 23:28

2 Answers2

5

You can give multifiles a try. From its README:

Bind a key to mf/mirror-region-in-multifile, let's say C-!. Now mark a part of the buffer and press it. A new multifile buffer pops up. Mark some other part of another file, and press C-! again. This is added to the multifile.

You can now edit the multifile buffer, and watch the original files change. Or you can edit the original files and watch the multifile buffer change.

Saving the multifile buffer will save all the original files.

Manuel Uberti
  • 3,150
  • 18
  • 36
1

The noccur package makes it easier to edit multiple (not-necessarily opened) files with multi-occur. After installing, this is an example of how to do a multi-occur edit:

  1. M-x noccur-project, and provide a search regexp and directory to be searched.
  2. In the multi-occur buffer that appears, type e to switch to edit mode.
  3. Make any changes to the multi-occur buffer that you want (e.g. using iedit-mode), and when finished, press C-c to save all changes.
Mark
  • 828
  • 10
  • 15