I have a number of files:

  • main.tex
  • chapter1.tex
  • chapter2.tex
  • chapter3.tex
  • chapter4.tex

The chapter files are linked in main.tex with the \input command.

In main.tex I define a named listing called sampletext that is also used throughout the chapters. I would like to rename this to examplecode in the main.tex and all the chapter files. How can I do this? I am using TexStudio on Windows.

  • 1
    Seems like more of a stackoverflow question to me. I'd suggest using using sed: sed -i.bak 's/sampletext/examplecode/g' *.tex, but, for Windows, the challenge may be getting a working version of sed up and running. (Not on Windows myself, however.)
    – jon
    Commented Sep 23, 2016 at 0:29
  • 3
    What I'd do is wipe Windows and install an OS which provides sed. However, you may consider that solution overkill.
    – cfr
    Commented Sep 23, 2016 at 0:39
  • Even if your editor provided that option, can you image the havoc it would cause with a mistake? Commented Sep 23, 2016 at 4:11
  • @cfr GOW provides sed and many other goodies on Windows: it's about 4 Mb so not a difficult install :)
    – Joseph Wright
    Commented Sep 23, 2016 at 8:00
  • @JosephWright On networked machines, it is an impossible install :(.
    – cfr
    Commented Sep 23, 2016 at 14:58

1 Answer 1


You can replace in multiple files in TeXstudio using the extended search:

  1. Search for the string to replace.
  2. Open the extended search using the [+] button in the search panel.
  3. Switch the scope from "Current Doc" to "Project".
  4. The search results list will be updated and show all matches.
  5. Type the new text in the field "Replace By" and press "Replace All"

enter image description here

Note: You can also deselect individual occurences using the checkboxes if you want to replace only a subset of all occurences.

  • If this is Texstudio (mentioned in OP), maybe you could make that a little clearer.
    – jon
    Commented Sep 23, 2016 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .