SyntaxT3rr0r
SyntaxT3rr0r

Reputation: 28293

Emacs: fastest way to open a file whose location is not known

What is the easiest way to open a txt file whose path has to be found using the shell find command?

For example, let say I want to open a file that I know is (uniquely) named example.txt and which I know is "somewhere I can find it using the shell find command".

What I do currently is this:

I do C-u (universal-argument) then M-! (shell command)

I then enter the find, for example:

find . -iname "example.txt"

Then the full path (which I didn't know previously) appears in the buffer, I cut it, then I hit C-x C-f, I delete what written by default and then paste what I cut before.

This seems a bit long and requires quite a few keystrokes, cut'n'pasting etc.

Is there an easiest way to do the same (without writing a new custom Emacs command)?

Upvotes: 11

Views: 2864

Answers (9)

Drew
Drew

Reputation: 30699

In Icicles you can find files by matching not just the relative file name but any parts of the path. You can use substring, regexp, and fuzzy matching. You can AND together multiple search patterns (progressive completion). See multi-command icicle-locate-file.

http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input

Upvotes: 1

Kabira  K
Kabira K

Reputation: 2007

I am surprised that globalff is not mentioned as one of the viable option. Sure it requires locate command but its quite fast and useful when you can't recall the exact name.

Upvotes: 0

Joseph Gay
Joseph Gay

Reputation: 800

Also have a look at LocateFilesAnywhere

I happen to use M-x anything-locate

Upvotes: 1

krakit
krakit

Reputation: 49

M-x locate is the fastest way to find and open a file, esp. if you know the exact filename, in emacs.

Upvotes: 3

Jérôme Radix
Jérôme Radix

Reputation: 10533

M-x find-dired RET

then you have a dired buffer showing your files returned by find. You can use classic dired command to open/move/rename... files and directories.

Upvotes: 0

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56595

If your folder constitutes a "project" - something under a version control or having a root folder marker such as project.el, .dir-locals.el, etc, you can use the find-file-in-project, which in my opinion is an excellent solution to this problem.

Upvotes: 2

scottfrazer
scottfrazer

Reputation: 17327

M-x find-name-dired

Enter the dir (defaults to current) and filename (shell globs work too) and you'll get a virtual dired buffer with the results. Go the file you want and hit 'a'

Upvotes: 10

Sean
Sean

Reputation: 29772

Using only built-in functionality, I would:

  • Go to a shell buffer: M-x shell
  • Run my find command.
  • Move the cursor up so that it's on top of the file path that was found.
  • Run the find-file-at-point command: M-x ffap.

I use find-file-at-point often enough that I have it bound to a dedicated key, s-\ (super-backslash).

Upvotes: 10

Trey Jackson
Trey Jackson

Reputation: 74440

Try out ifind.el

M-x ifind /some/starting/point/example.txt

Will search for example.txt in directories below /some/starting/point.

Upvotes: 6

Related Questions