Skip to content

Latest commit

 

History

History
140 lines (97 loc) · 3.55 KB

Emacs-10.org

File metadata and controls

140 lines (97 loc) · 3.55 KB

Effortless File Management with Dired

Check out the GitHub repo

https://github.com/daviwil/emacs-from-scratch

Dired Basics

Invocation

  • C-x d or C-x C-f - dired
  • dired-jump - open Dired buffer, select the current file
  • projectile-dired

Navigation

Emacs / Evil

  • n / j - next line
  • p / k - previous line
  • j / J - jump to file in buffer
  • RET - select file or directory
  • ^ - go to parent directory
  • S-RET / g O - Open file in “other” window
  • M-RET - Show file in other window without focusing (previewing files)
  • g o (dired-view-file) - Open file but in a “preview” mode, close with q

Configuration

  • dired-listing-switches: Try -agho --group-directories-first
  • g / g r Refresh the buffer with revert-buffer after changing configuration (and after filesystem changes!)
    (use-package dired
      :ensure nil
      :commands (dired dired-jump)
      :bind (("C-x C-j" . dired-jump))
      :config
      (evil-collection-define-key 'normal 'dired-mode-map
        "h" 'dired-up-directory
        "l" 'dired-find-file))
    
        

File Operations

Marking files

  • m - Marks a file
  • u - Unmarks a file
  • U - Unmarks all files in buffer
  • * t / t - Inverts marked files in buffer
  • % m - Mark files in buffer using regular expression
  • * - Lots of other auto-marking functions
  • k / K - “Kill” marked items (refresh buffer with g / g r to get them back)
  • Many operations can be done on a single file if there are no active marks!

Copying and Renaming files

  • C - Copy marked files (or if no files are marked, the current file)
  • Copying single and multiple files
  • U - Unmark all files in buffer
  • R - Rename marked files, renaming multiple is a move!
  • % R - Rename based on regular expression: ^test , old-\&

Deleting files

  • D - Delete marked file
  • d - Mark file for deletion
  • x - Execute deletion for marks
  • delete-by-moving-to-trash - Move to trash instead of deleting permanently

Creating and extracting archives

  • Z - Compress or uncompress a file or folder to (.tar.gz)
  • c - Compress selection to a specific file
  • dired-compress-files-alist - Bind compression commands to file extension

Other common operations

  • T - Touch (change timestamp)
  • M - Change file mode
  • O - Change file owner
  • G - Change file group
  • S - Create a symbolic link to this file
  • L - Load an Emacs Lisp file into Emacs

Single Dired buffer

Closed Dired buffers are just buried! They need to be refreshed if you go back to them.

Use dired-single to help with this: https://github.com/crocket/dired-single

;; Inside `use-package dired`
(use-package dired-single)

    (evil-collection-define-key 'normal 'dired-mode-map
      "h" 'dired-single-up-directory
      "l" 'dired-single-buffer))

File icons

(use-package all-the-icons-dired
  :hook (dired-mode . all-the-icons-dired-mode))

Open external files

  • ! or & to launch an external program on a file
(use-package dired-open
  :config
  ;; Doesn't work as expected!
  (add-to-list 'dired-open-functions #'dired-open-xdg t)
  ;; -- OR! --
  (setq dired-open-extensions '(("png" . "feh")
                                ("mkv" . "mpv"))))

Hide / show dotfiles

(use-package dired-hide-dotfiles
  :hook (dired-mode . dired-hide-dotfiles-mode)
  :config
  (evil-collection-define-key 'normal 'dired-mode-map
    "H" 'dired-hide-dotfiles-mode))