Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

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)?

like image 801
SyntaxT3rr0r Avatar asked Sep 29 '10 13:09

SyntaxT3rr0r


People also ask

What is CX CF in Emacs?

Emacs makes a new buffer for each file that you visit. To visit a file, type C-x C-f ( find-file ) and use the minibuffer to enter the name of the desired file. While in the minibuffer, you can abort the command by typing C-g .

How do I open an existing Emacs file?

Use Ctrl-x f to open a file from within Emacs. Create a new file in the same way as opening a file by specifying the new filename.

How do I find a file in Emacs?

To find a file in Emacs, you use the C-x C-f ( find-file ) command.

What is the command to display file information in Emacs?

Emacs can list the names of the files in a directory as a Lisp list, or display the names in a buffer using the ls shell command. In the latter case, it can optionally display information about each file, depending on the options passed to the ls command.


2 Answers

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).

like image 129
Sean Avatar answered Sep 19 '22 15:09

Sean


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'

like image 35
scottfrazer Avatar answered Sep 18 '22 15:09

scottfrazer