Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find several files with one command in Emacs

Tags:

emacs

I would like to know Emacs' equivalent of Vim's :n, which opens several files according to a glob.

Say I have this directory:

-rw-rw-r-- 1 pablo pablo 31 Jun 25 00:59 /home/pablo/tmp/prueba.php
-rw-rw-r-- 1 pablo pablo 2442 May 9 1913 /home/pablo/tmp/sin_soap.php
-rw-rw-r-- 1 pablo pablo 726 Jun 25 15:20 /home/pablo/tmp/verificar.php

And I want to open all those files. In Vim, I can type

:n *php

and that will give me one buffer for every file; I don't know how to do that in Emacs (when it's already open, of course I can do 'emacs *php' in a shell).

I'm happy with a function that I can call from any buffer via M-x, but if there's a command that I can call in dired-mode (say, edit all marked files or something), that would be beyond cool.

Thanks.

like image 820
ptn777 Avatar asked Aug 30 '10 03:08

ptn777


People also ask

How do I find files in Emacs?

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

How do I open multiple files in Emacs?

Much better to use the multiple buffer feature of emacs. If you are editing the first file and want to start editing the second file, simply use the hot key C-x C-f or the menu selection File->Open File to start the second file. The second file is loaded into its own buffer.

How do I navigate to a folder in Emacs?

In Emacs, type M-x dired. You will be prompted for the directory to open. Type in the directory to display, or press Return to open the default directory.

How do I copy files in Emacs?

M-x copy-file copies the contents of the file old to the file new . M-x copy-directory copies directories, similar to the cp -r shell command. If new is a directory name, it creates a copy of the old directory and puts it in new . Otherwise it copies all the contents of old into a new directory named new .


1 Answers

The ordinary find-file command, C-xC-f, will accept wildcards and open multiple buffers. From the documentation:

Interactively, or if wildcards is non-nil in a call from Lisp, expand wildcards (if any) and visit multiple files. You can suppress wildcard expansion by setting `find-file-wildcards' to nil.

In your example you'd just type C-xC-f*phpRET.

like image 160
Sean Avatar answered Nov 13 '22 10:11

Sean