How to adjust dired-omit-mode



  • When dired is opened by default hidden files should be hidden.
  • When the user clicks “M-q” hidden files must be shown except for “.” and “..”

I tried the following:

;don't show hidden files
(setq dired-omit-files "^\\..*$")
(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")

(add-hook 'dired-mode-hook
          (lambda ()
            (setq dired-omit-mode t)
            (define-key dired-mode-map (kbd "M-q") 'swap-omit-files)
Hidden file are indeed hidden by default, but something is wrong with swap-omit-files --- the hidden files are not shown.

How to fix?

shareimprove this question


This worked. We needed to revert-buffer after changing dired-omit-files:

(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")
shareimprove this answer

After enabling ivy-mode, `dired-create-directory’ does not allow me to choose an entry not in the completion list


Yes, obviously.

There are 2 cases. The name you want to create doesn’t match anything in the completion list, or when it does.

When it doesn’t, you can just do the totally obvious thing, type in the name and press enter.

If it does match, then pressing enter will get ivy to expand the name to the completion. Here you want to call ivy-immediate-done which is bound to C-M-j by default after you have typed the name.

shareimprove this answer

Emacs Dired rename many files


This can easily be done using dired:

  1. Enter a dired view of your directory
  2. Switch to writable dired mode (wdired-change-to-wdired-mode): C-xC-q
  3. Edit the file names listing as if it were a normal buffer (for example using a keyboard macro or a rectangular selection or query-replace). Here is a regexp-based solution:


  4. Finish editing (wdired-finish-edit): C-xC-s or C-cC-c

You’re done!


Emacs: Rename Files Interactively


Emacs: Rename Files Interactively

Buy Xah Emacs Tutorial. Master emacs benefits for life.

This pages shows you how to rename multiple files in emacs.

Go to the directory first, by calling dired. 〔➤ Emacs: File Management (dired tutorial)

When in dired, call dired-toggle-read-onlyCtrl+x Ctrl+q】.

Then, just edit the file names.

When done, do one of:

  • wdired-finish-editCtrl+c Ctrl+c】 to commit the changes.
  • wdired-abort-changesCtrl+c Ctrl+k】 to abort the changes.

How to quickly copy/move file in Emacs Dired?

From the documentation:

dired-dwim-target is a variable defined in `dired.el’. Its value is nil

Documentation: If non-nil, Dired tries to guess a default target directory. This means: if there is a Dired buffer displayed in the next window, use its current directory, instead of this Dired buffer’s current directory.

The target is used in the prompt for file copy, rename etc.

Put this in your init file: (setq dired-dwim-target t). Then, go to dired, split your window, split-window-vertically & go to another dired directory. When you will press C to copy, the other dir in the split pane will be default destination.

shareimprove this answer