Dynamically filter directory listing with dired-narrow

If you install the package dired-narrow (one of several neat packages described on the dired-hacks github page), then you can type filter strings to dynamically filter down a dired listing to match the filter.

For example, in the animation below I have a dired buffer containing lots of files. I invoke dired-narrow by hitting / and then type “png” to narrow to filenames matching “png”. I then hit RET to complete the filtering. At that point I can operate on the filtered dired list as I would for any dired buffer. I can even narrow further by simply invoking dired-narrow again and typing a new filter (I use “mirror” in the example below). Once I have finished with the filter, I hit g to revert back to the full directory listing.


As an aside, I have started using use-package to install and configure packages (see the update on this page). Here is the code I use to install and set up dired-narrow.

;;narrow dired to match filter
(use-package dired-narrow
  :ensure t
  :bind (:map dired-mode-map
              ("/" . dired-narrow)))
  • Cool, thanks for the tip!

    I had to add a (use-package dired) or else I got “Symbol’s value as variable is void: dired-mode-map”.

    • Oops, never mind. I just did a ‘cask update’ and the problem went away. This included ‘use-package 20160204.1100 -> 20160226.1618’, so I guess that was it…?

      Thanks again!

      • Yes – I think the :map option was added in a very recent version of use-package

  • Mike F

    In the video for dired-hacks there is a gold colored area of the mode line which is indicating the current object size. Is this part of the powerline library? Maybe just the coloring is from powerline?

    • This is using the spaceline package. Try using this code

      (use-package spaceline-config
      :ensure spaceline