Kei Minagawa
Kei Minagawa

Reputation: 4521

How to open a directory of current buffer that is opening a file using just one command in Emacs?

Is there any simple command to do this? I'm tired to type C-x C-f ENTER.

Upvotes: 0

Views: 414

Answers (2)

phils
phils

Reputation: 73345

If you (require 'dired-x) in your init file (or alternatively follow the autoloading instructions1), you can use C-xC-j to call dired-jump, which not only does what you want (in both file-visiting buffers and also in dired buffers), but also places point on the dired entry for the file or directory that you have just come from, which can be incredibly convenient.

1 C-hig (dired-x) Optional Installation Dired Jump RET

Upvotes: 5

user2053036
user2053036

Reputation:

There isn't a single command to do that as far as I know, but since you are using emacs you can easily define one. Add these to your init file

(defun my-open-dired-here ()
  (interactive)
  (dired default-directory))

The above defines a command to open dired in current buffer's directory, this is what you get when you do C-x C-f RET in vanilla emacs.

You can bind the above command to a key of your choice I am binding it to F6

(global-set-key (kbd "<f6>") 'my-open-dired-here)

Now when you press F6 you will get dired opened in current buffer's directory.

Upvotes: 3

Related Questions