-
-
Notifications
You must be signed in to change notification settings - Fork 390
Find Files
- Usage
- Navigation
- Actions
- Create
- Open files externally
- Rename/move
- Serial rename
- Mark files using wildcard
- Query replace on filenames
- Open a wdired buffer with marked files for edit
- Copy/rename
- Copy with Rsync
- Symlink
- Hardlink
- Follow file after action
- Insert file name
- Ediff
- Eshell command on files
- Browse images
- Browse archives with AVFS
helm-find-files
is Helm’s version of find-files
; it allows easy navigation of file hierarchies.
By default, it is bound to <helm-prefix> C-x C-f
. You can also find it in the menu (Tools > Helm > Files > Find files). For convenience, you should bind it to C-x C-f
.
Using universal argument (C-u
) displays a history of previously visited directories.
helm-find-files
starts at default-directory
or thing-at-point
, the latter of which it gets from ffap
. If you are on a URL, mail address, etc., it will do the right thing.
Some common actions and corresponding keys are below:
Action | Key |
---|---|
Move up | C-p |
Move down | C-n |
Persistent action | C-z |
Up directory | C-l |
C-j
and C-z
execute the persistent action, which differs depending on context. The persistent actions for different file types are below:
Type | Persistent Action |
---|---|
File | Shows file name in the Helm buffer. |
Directory | Steps into the directory. |
Symlink | Expand to symlink’s true name |
Navigate to the directory where you want to create the new file, then type the file’s name and hit RET
. If the name ends in a slash (/
), Helm prompts you to create a directory (possibly with parent directories).
In the action menu, the Open files externally
action (bound to C-c C-x
by default) can open a file with an external program.
Mark some files and select the Rename file(s)
action in the action menu. If the new name is in the current directory, the file is renamed. If it is in another directory, the file is moved there.
Most of the time you will not need this and prefer Query replace on filenames or wdired.
You can rename files with a prefix and incremental numbering. Marked files will be renamed with the prefix and number starting at the one given.
Tip:
- If you have more than 100 files to serial rename, start at 100 instead of 1 to have your directory sorted correctly.
Marked files are renamed in order of selection. If you mark files in directories other than the current one, the files will be moved or symlinked to the current one.
There are three methods to serial rename files:
Method | Description |
---|---|
Rename | Files in other directories are moved to the target directory. |
Symlink | Files in other directories are symlinked; those in the current directory are renamed. |
Copy | Files in other directories are copied to the target directory. |
Suppose we want to create a directory with many symlinks to images from multiple directories.
- Execute
helm-find-files
. - Navigate to the parent directory of the target directory, create the target directory (with name ending in
/
), and hitRET
. - Navigate to images in other directories and mark them.
-
M-a
marks all files in a directory.
-
- After marking all files, choose
serial rename by symlinking
from the action menu. - Choose prefix and start number.
- Navigate to the target directory and hit
RET
. - Confirm.
Use of wilcard is supported to give a set of files to an action:
e.g. You can copy all the files with .el
extension by using *.el
and then run your copy action.
You can do the same but with **.el
(note the two stars),
this will select recursively all .el
files under current directory.
NOTE: When using an action that involve an external backend (e.g. grep), using **
is not advised (even if it works fine) because it will be slower to select all your files,
you have better time letting the backend doing it, it will be faster.
However, if you know you have not many files it is reasonable to use this,
also using not recursive wilcard (e.g. *.el
) is perfectly fine for this.
This feature (**
) is activated by default with the option helm-file-globstar
.
The directory selection with **foo/
like bash shopt globstar option
is not supported yet.
You can rename your files by replacing only part of filenames matching
a regexp.
e.g Rename recursively all files with .JPG
extension to .jpg
:
Use the helm-file-globstar
feature described in previous section by
entering at end of helm-find-files
pattern **.JPG
, then hit M-%
,
at first prompt enter JPG
, at second jpg
and hit RET
.
When you want to rename a set of files (marked) you can open a dired
buffer with only those files, you can then edit these files as wanted
by switching to wdired and use query-replace or iedit etc…
To do this, mark some files and hit C-x C-q
, to switch to wdired hit
again C-x C-q
(a shortcut is to use a prefix arg on first C-x C-q
hit).
With helm-find-files
, you can mark files in different directories
and copy or rename them to a target directory.
Mark some files in various directories and select the Copy file(s)
or Rename file(s)
action in the action menu.
If you have a system compatible with Rsync and Rsync is installed you can use Rsync to sync files, it is recommended to use this for large files (e.g. movies, images etc…), see embeded helm-find-files documentation for more infos.
Mark some files and select the Symlink file(s)
or Relsymlink file(s)
action in the action menu. A new helm-find-files
session appears in which you can select where the symlink will be.
Mark some files and select the Hardlink file(s)
action in the action menu. A new helm-find-files
session appears in which you can select where the hardlink will be.
A prefix argument on any of the following actions will follow the file:
- Rename
- Copy
- Symlink
- Hardlink
For example, when you want to copy a .elisp
file somewhere and compile it there, hitting C-u RET
will go to the destination with the file already marked. You can then select Byte compile lisp file(s)
to compile it.
In any buffer (including the minibuffer, if enable-recursive-minibuffers
is t
), you can get insert the file name at point by selecting Complete at point
from the action menu.
Move cursor to a file and choose Ediff file
in the action menu. A new helm-find-files
session allows you to choose a second file with which to diff with the first.
The Ediff merge file
action is similar, but allows merging files.
You can run eshell-command
on a file or marked files. The command must accept a single file as an argument.
Completion is made on your Eshell aliases. This allow you to creating custom actions for
helm-find-files
.
We use Eshell because it:
- Allows aliases
- Accepts both shell commands and Emacs Lisp functions
To create an alias in Eshell, enter the following at the prompt:
alias my_alias command $1
NOTE:
- Don’t forget the escape the
$
.
See the Eshell aliases documentation for more information.
Most Eshell commands are available only after Eshell has been started once. To start Eshell on Emacs startup, add the following to your init file:
(add-hook 'emacs-startup-hook (lambda ()
(let ((default-directory (getenv "HOME")))
(command-execute 'eshell)
(bury-buffer))))
helm-find-files
and its persistent actions make for a fine image browser.
The following requires image-dired (built-in) and ImageMagick.
- Navigate to a directory with images.
- Hit
C-u C-z
on first image. - Turn on
follow-mode
withC-c C-f
.
Now, you can navigate the image directory with the <up>
and <down>
arrow keys, or C-n
and C-p
. You can also use C-t
to split windows vertically and C-}
, C-{
to shrink/enlarge the Helm window.
In the action menu, there are actions to rotate an image.
Action | Key |
---|---|
Rotate left | M-l |
Rotate right | M-r |
If you have AVFS installed, you can browse archives in your .avfs
directory once it is mounted with
mountavfs
.
Move to the archive filename and choose persistent action (C-z
), and you will see a Helm buffer containing the archive’s sub-directories.