Editing your file names

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:

Emacs-Dired

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.

About these ads

11 Responses to “Editing your file names”

  1. aaron Says:

    Very cool.

    You mean `M-%’, not `M-$’.

  2. jao Says:

    aaron, absolutely. thanks.

  3. Derek Says:

    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).

  4. Pupeno Says:

    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.

  5. labsji Says:

    Cool trick.
    Dired is handy when you are dealing with files with funny characters.

  6. Paul Huff Says:

    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.

  7. Jeff Martens Says:

    Very useful–thanks!

  8. Scott Young Says:

    Thank you very much for the tips!

  9. denki0tokage Says:

    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…..

  10. Joonhwan Says:

    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.

  11. Maribeth Boyles Says:

    Neat blog! Is your theme custom made or did you download it from somewhere?
    A design like yourss with a few simple adjustements would reallpy make
    my blog jump out. Pleaxe let mme know where you got your design. Thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: