In my experience, dired is one of the most underused modes of Emacs. Just C-xC-f to any directory in your hard disk and you’ll be presented with a list of its files and directories. One can browse this list, and execute all kinds of commands and transformations on them. If you’ve never done that before, just give it a try, and look at the menubar for a list of nifty things you can do inside dired. There’re several ways to mark files and operate on them afterwards: for instance, just type A to find inside the selected files any regexp, or Q to search and substitute.
One of my favorites dired functionalities is wdired-change-to-wdired-mode. When you invoke this interactive function (using M-x wdired-change-to-wdired-mode), the dired buffer becomes editable. That is, you can go around and edit directly the filenames as you would edit any other emacs text buffer. And that means you have all the regular editing commands at your disposal. For instance, if i enter wdired-mode in my emacs configuration directory:
and want to change the name of all those jao-*.el files to, say, jao-config-*.el, all i have to do is to search and replace as i would do in any other text file (i.e., using M-%). Or maybe put the cursor on the first file name, mark (C-SPC), got to the end of the jao-files list, put my cursor after the last dash (as shown in the figure), and use C-xrt to replace the text in the marked rectangle. When you’re happy editing the buffer, just press C-cC-c and all your changes will be reflected in the underlying files.
Nifty.
January 15, 2007 at 2:02 pm
Very cool.
You mean `M-%’, not `M-$’.
January 15, 2007 at 2:04 pm
aaron, absolutely. thanks.
January 15, 2007 at 9:10 pm
Good stuff — note that wdired.el doesn’t ship with Emacs 21. The latest version I could find is in Emacs CVS (the EmacsWiki version is slightly out-of-date).
January 16, 2007 at 4:29 pm
Nice tip.
I am using Emacs as the less-sucky editor out there and I don’t really know how to use it (I just know that when I pick another editor, things get worse) so I’ve added this feed to my feed reader hoping to improve my Emacs skills.
Thank you.
January 16, 2007 at 6:33 pm
Cool trick.
Dired is handy when you are dealing with files with funny characters.
January 16, 2007 at 6:34 pm
Another thing I like about dired mode is that it lets you edit tarballs. Fire up dired, hit enter on your tarball and it opens it up as if it were just another subdirectory. Pretty sweet.
April 8, 2011 at 1:22 am
Very useful–thanks!
May 11, 2011 at 4:30 pm
Thank you very much for the tips!
January 29, 2013 at 11:42 pm
Reblogged this on Ah… naruhodo ne! und kommentierte:
The nice thing about Emacs is that every time I go looking I find some more built-in functionality that saves even more time…..
March 29, 2013 at 12:30 pm
I’m using C-x C-q to call wdired-change-to-wdired-mode in dired buffer.
This is handy and consistent keybindings, becuase it calls toggle-read-only when in normal editing buffers.