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.
  • Phil

    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.

    • Phil

      My apologies, it's not exactly the same effect. It is pleasingly similar, though!

  • And what a great way to make all your "printf" into "prlongf".

  • Aankhen

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

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

    M-x load-library RET dired-x RET