1

In normal file managers like nautilus, if i select an item and press delete button, it will delete that item.

How can i achieve the same in dired? When point is at file, pressing delete button should delete that item?

2 Answers 2

2

If you use library Dired+ then the delete key is bound by default to to command diredp-delete-this-file, which deletes the file named on the line of the cursor, after confirmation. (C-k is bound to the same command.)

This is the entire definition of the command:

(defun diredp-delete-this-file ()       ; Bound to `C-k', `delete'
  "In Dired, delete the file on the cursor line, upon confirmation."
  (interactive) (dired-do-delete 1))
0

We can write a simple function to delete file at point and then bind it to delete button.

(defun delete-current-item ()
  "Delete file at point"
  (interactive)
  (dired-flag-file-deletion 1)
  (dired-do-flagged-delete))

(define-key dired-mode-map  [delete] 'delete-current-item)
1
  • 2
    You may wish to check out the function dired-do-delete attached to the capital letter D, which will give a confirmation and then delete the file at point if the user says yes -- no need to flag, etc.
    – lawlist
    Commented Sep 16, 2015 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.