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

It is defined in the built-in Dired X package, so need to load that:

    (add-hook 'dired-load-hook '(lambda () (require 'dired-x))) ; Load Dired X when Dired is loaded.
    (setq dired-omit-mode t) ; Turn on Omit mode.

‘C-x M-o’ (‘M-o’ in older versions of Emacs) in Dired buffers toggles hiding of files. Variables ‘dired-omit-files’ and ‘dired-omit-extensions’ together define the uninteresting files. (Versions of Emacs before 22.1 used ‘dired-omit-files-p’).

With most recent Emacs versions no hooks are needed and the following lines in your init file enable omit mode (in this example dot files are omitted):

    (require 'dired-x)
    (setq-default dired-omit-files-p t) ; Buffer-local variable
    (setq dired-omit-files (concat dired-omit-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.) Usually you will want to remove -a from the switches, to hide dot files.

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