7

Let's say I am editing blah.txt with Emacs and I decide to open dired to rename the file blah.txt. When I press C-x d RET (or C-x C-f RET), a dired buffer will show up to display the content of the directory containing blah.txt, but the cursor will not be on blah.txt. So I need to search my file first (C-s blah.txt) to place my cursor on it and then I can rename it (R).

How do I automate or remove the step C-s blah.txt?

Community
  • 1
  • 1
Yoo
  • 17,526
  • 6
  • 41
  • 47

6 Answers6

12

dired-jump is exactly what you want.

(autoload 'dired-jump "dired-x" "Jump to dired corresponding current buffer.")
(autoload 'dired-jump-other-window "dired-x" "jump to dired in other window.")

Then call:

M-x dired-jump

or

M-x dired-jump-other-window
Tao Peng
  • 2,688
  • 22
  • 20
  • If you follow the instructions in the manual, you'll get the correct key bindings as well: `C-h i g` `(dired-x) Optional Installation Dired Jump` `RET` – phils Aug 23 '14 at 06:25
5

You want C-x C-j.

offby1
  • 6,767
  • 30
  • 45
2

Sunrise Commander is a much improved dired. and it does what you need by default.

VitoshKa
  • 8,387
  • 3
  • 35
  • 59
1

You can do something like that:

M-: (dired (buffer-name (current-buffer)))

Then the only file visible in dired will be your current file and cursor will be right on it.

Alexey Voinov
  • 1,106
  • 1
  • 7
  • 8
1

This piece of advice will do what you want:

(defadvice dired (around dired-jump-to-buffer activate)
  "When running dired, move cursor to the line for the buffer we came from"
  (interactive (list nil nil)) ;; bogus values, will be overwritten below
  (let ((coming-from (buffer-file-name)))
(ad-set-args 0 (dired-read-dir-and-switches ""))
ad-do-it
(when (and coming-from
       (equal (file-truename default-directory) (file-truename (file-name-directory coming-from))))
    (goto-char (point-min))
    (search-forward (file-name-nondirectory coming-from) nil t))))

Note: Works for C-x d, but not the C-x C-f entry point to dired.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
0
$ emacs --version
GNU Emacs 24.3.1

In .emacs:

(require 'dired-x)

Now C-x C-j should be bound to dired-jump.

Jackson
  • 9,188
  • 6
  • 52
  • 77