4

How does one find and replace text in all open files with gedit?

Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
CW Holeman II
  • 3,654
  • 5
  • 31
  • 49

2 Answers2

9

This is not possible with a stock gedit; there's an open ubuntu brainstorm idea for adding the ability. However, there are plugins that add it, such as advanced-find. If you install that, one of the sections on the "Advanced Find/Replace" dialog is "Scope"; choose "All Opened Documents":

Screenshot of the Advanced Find/Replace dialog

Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
2

Generally people who want to do this write an ed script and run it against all the files. E.g.:

*s/ThrityLimit/ThirtyLimit/
w
q

And then run it like this

find . -name '*.c' -exec "ed <edscript"

You can also use an ex script which allows you to use all the : commands from vi. It's the same binary as vi just called using the command ex to start without the gui.

Michael Dillon
  • 895
  • 4
  • 8
  • 1
    or with GNU sed: `sed -i -e 's/ThrityLimit/ThirtyLimit/g' *.c`. Or `perl -i -pe 's/ThrityLimit/ThirtyLimit/g' *.c`. With zsh or bash 4, you can traverse subdirectories with `**/*.c`. – Gilles 'SO- stop being evil' Feb 24 '11 at 20:53
  • "How does one find and replace text in all open files" indicates that the user already has selected which files to apply the edit to. This answer does not address that aspect of the question nor does it address the "with gedit" component. – CW Holeman II Mar 14 '18 at 18:34