This page is about Omit Mode in Dired, which lets you hide uninteresting files, such as backup files and AutoSave files.

‘C-x M-o’ in Dired buffers toggles this mode.

To enable omitting in every Dired buffer, you can use:

    (add-hook 'dired-mode-hook (lambda () (dired-omit-mode)))

Variables ‘dired-omit-files’ and ‘dired-omit-extensions’ together define the uninteresting files.

Coloring Dot Files?

One thing that I want is for dot-files (e.g., .bashrc, .emacs, etc.) to be colored in the same dim face that the other uninteresting files are colored in. I use (setq dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$\\|^\\..*$"), which hides my dot files when I hit ‘M-o’, but these files aren’t colored in the dim face.

That dims only the files that match the extensions in ‘dired-omit-extensions’, but obviously this won’t work for dot files. Does anyone have a work-around for this? Thanks. – parolang

See Dired+ for a way to color less-interesting files differently in Dired. Combined with Omit mode, this can do either of the following:

No Omit Mode for `recover-session'

Dired ignores *~ files, which are used by ‘recover-session’. The following turns on omit mode except when running ‘recover-session’:

   (defun enable-dired-omit-mode () (dired-omit-mode 1))
   (add-hook 'dired-mode-hook 'enable-dired-omit-mode)
   (defadvice recover-session (around disable-dired-omit-for-recover activate)
     (let ((dired-mode-hook dired-mode-hook))
       (remove-hook 'dired-mode-hook 'enable-dired-omit-mode)

Toggle Showing Dot Files

  (defun dired-dotfiles-toggle ()
    "Show/hide dot-files"
    (when (equal major-mode 'dired-mode)
      (if (or (not (boundp 'dired-dotfiles-show-p)) dired-dotfiles-show-p) ; if currently showing
	    (set (make-local-variable 'dired-dotfiles-show-p) nil)
	    (message "h")
	    (dired-mark-files-regexp "^\\\.")
	(progn (revert-buffer) ; otherwise just revert to re-show
	       (set (make-local-variable 'dired-dotfiles-show-p) t)))))


Remember Omit State

I prefer that Dired remember my omit state: when enabling/disabling ‘omit-mode’, the ‘omit-mode’ remains enabled/disabled in another Dired buffer. This code does that:

   (defvar v-dired-omit t
     "If dired-omit-mode enabled by default. Don't setq me.")
   (defun dired-omit-switch ()
     "This function is a small enhancement for `dired-omit-mode', which will
   \"remember\" omit state across Dired buffers."
     (if (eq v-dired-omit t)
         (setq v-dired-omit nil)
       (setq v-dired-omit t))
   (defun dired-omit-caller ()
     (if v-dired-omit
         (setq dired-omit-mode t)
       (setq dired-omit-mode nil)))
   (define-key dired-mode-map (kbd "C-x M-o") 'dired-omit-switch)
   (add-hook 'dired-mode-hook 'dired-omit-caller)


Using `ls' Switches Instead of Omit Mode

An alternative to using Omit mode: Use ‘C-u s’ to change the ‘ls’ switches and immediately refresh. (‘C-u s’ refreshes also, so there is very little typing involved.) You can remove -a from the switches to hide dot files, or add -B to hide files ending with ~.

With this approach you can do everything you can do in the shell console, which is far more than what a simple Omit mode toggle can offer (at the cost of some extra keypresses). And there is a history of previous flags available, so toggling is pretty fast with this approach also. – 190-216-58-35.static.impsat.net.ar

Omit mode has a problem when you use C-x C-s to save multiple files and have dired buffers open. The message “Omitted x files.” overwrites the promt that asks you what file to save. Using ls switches works better. Here is my config

 (setq my-dired-ls-switches "-alh --ignore=.* --ignore=\\#* --ignore=*~")
 (setq my-dired-switch 1)
 (add-hook 'dired-mode-hook
           (lambda ()
             "Set the right mode for new dired buffers."
             (when (= my-dired-switch 1)
               (dired-sort-other my-dired-ls-switches))))
 (add-hook 'dired-mode-hook
           (lambda ()
             (define-key dired-mode-map (kbd "M-o")
               (lambda ()
                 "Toggle between hide and show."
                 (setq my-dired-switch (- my-dired-switch))
                 (if (= my-dired-switch 1)
                     (dired-sort-other my-dired-ls-switches)
                   (dired-sort-other "-alh"))))))