dired Emacs directory editorλ︎
A Dired buffer displays the contents of a single directory or listings of one or more sub-directories. A Dired buffer can display an arbitrary set of files and directories from any file systems.
dired mode is built-in to Emacs (version 23 onward)
Space f f and select the
. root of a directory to open a directory listing in dired
Space f j or Space j d to jump to the current buffer in a dired buffer. Space j D opens dired buffer in a different window.
Use Evil style navigation and editing with the dired buffer
wdired-change-to-wdired-mode WDired mode (writable dired) enables editing of the dired buffer. Names of the files in the buffer, the target of symbolic links and the permission bits of the files can be changed.
m mark files to run an action across multiple files in the listing
|mark / unmark meun
|rename a file
|flag for deletion
|^ or -
|move up a directory
Rename files with WDired modeλ︎
The names in a dired directory listing can be renamed by editing the file names in the dired buffer and committing the changes.
Space f f and select the . root of a directory to open a directory listing in dired (or switch to an open dired buffer).
wdired-change-to-wdired-mode to make the dired buffer writable. The cursor enters insert mode and is placed on the top entry of the directory listing.
Ctrl+c Ctrl+c to commit the changes and update all the affected files.
Ctrl+c Esc to cancel all changes.
Small changes often
Undo is not available in this mode, so make simple changes and save the results as soon as possible.
Emacs macro for multiple file renamesλ︎
Record a macro to rename a file and run the macro over multiple lines in the dired buffer in WDired mode.
q a in normal mode will start recording all following key bindings
q again to stop recording and save all the key bindings as a macro bound to the a character.
Any character other than q can be used as the macro name and Practicalli finds a, z and x as convenient characters for macros.
@ a to run the macro and repeat the same change
2 4 @ a to run the macro on the next 24 lines including the current line, repeating the same change on multiple file names in the dired buffer.
Reset cursor position at end of macro
If using positional aspects for changes made by the macro ensure the cursor is moved back to the correct starting place just before ending the macro recording.