Text Replacement In Several Files With Emacs

Just a quickie. I was browsing around in Aaron Hawley’s Giant Emacs Reference Sheet when I came across this little ditty:

C-x d *.c RET Q int RET long    

It was described as “replace ‘long’ for ‘int’ in .c files.” I thought, “Boy, that’s really handy” and then I realized that it’s just

  1. Enter dired and list all the .c files
  2. Do a query replace substituting long for int

something that I’ve probably blogged about in the past.

Still, it does seem to gain power when you think of it as one command. And, if for only a moment, I thought I’d found something new and wonderful.

This entry was posted in General and tagged . Bookmark the permalink.

5 Responses to Text Replacement In Several Files With Emacs

  1. Phil says:

    I like how *.c RET has exactly the same effect from within dired as it does at the C-x d prompt, even though it’s for different reasons (filename globbing vs dired-mark-extension). I never really use C-x d to invoke dired, so I hadn’t noticed this nice piece of consistency before.

  2. Erez Schatz says:

    And what a great way to make all your “printf” into “prlongf”.

  3. Aankhen says:

    Q does a query replace, so you’d have to actively work to make that happen. ;-)

  4. Peter Reavy says:

    The *.c didn’t work for me but I had not got dired-x loaded.

    M-x load-library RET dired-x RET

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>