Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open dired and select the file associated with the previous buffer?

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?

like image 364
Yoo Avatar asked Oct 14 '10 13:10

Yoo


4 Answers

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
like image 139
Tao Peng Avatar answered Nov 12 '22 02:11

Tao Peng


You want C-x C-j.

like image 36
offby1 Avatar answered Nov 12 '22 01:11

offby1


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

like image 39
VitoshKa Avatar answered Nov 12 '22 00:11

VitoshKa


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.

like image 1
Alexey Voinov Avatar answered Nov 12 '22 01:11

Alexey Voinov