Dzung Hong
Dzung Hong

Reputation: 43

A quick way to do find-file in Emacs?

Every time I use find-file in Aquamacs or Emacs, it auto shows the previous directory, for example ~/Work/abc/cdf. However, if I want to open something from the ~ directory, I have to press Delete all the ways down to the first character. Is there any quick way to replace all the string with just one or two keys?

Thank you in advance.

Upvotes: 4

Views: 742

Answers (6)

Drew
Drew

Reputation: 30699

(defun foo ()
  "Clear the minibuffer"
  (interactive)
  (delete-minibuffer-contents))

(define-key minibuffer-local-map [(meta ?k)] 'foo)

Upvotes: 0

Rörd
Rörd

Reputation: 6681

As harpo has already noted, just entering ~ will do the job for changing to home directory quickly. More generally, you can get a lot of improvements for quicker navigation in find-file by activating ido-mode.

Upvotes: 2

Lindydancer
Lindydancer

Reputation: 26104

There are packages that does that for you, for example:

http://www.emacswiki.org/emacs/minibuf-electric-gnuemacs.el

Upvotes: 0

Chris Stratton
Chris Stratton

Reputation: 40367

how about M-<DEL> (backward-kill-word)

Should take one press per directory level

C-x <DEL> (backward-kill-sentence)

works but also wipes out the ~/

You can of course define your own commands and the emacs lisp to implement them.

As an alternate approach, many unixes will let you simply type a ~/ after the prefilled path and put your desired path after that, the ~/ overriding everything that came before.

Upvotes: 0

harpo
harpo

Reputation: 43168

No, you don't (have to press Delete). Just type ~ and emacs will ignore everything before it. Same with /.

Upvotes: 11

Bogatyr
Bogatyr

Reputation: 19323

Yes, while still in the mini buffer press Ctrl-A to go to the start of the file name path, and Ctrl-K to delete it to the end of the line, now your file path is empty and you can just type "~"

Upvotes: 2

Related Questions