-
-
Notifications
You must be signed in to change notification settings - Fork 389
Locate
helm-locate
(<helm-prefix> l
by default) is Helm’s interface to the locate command, which finds files on your system that have been indexed with updatedb.
The exact command for helm-locate
can be customized through the variable helm-locate-command
. The default value works on most locate
versions and variants.
On more recent versions of locate
, you may want to use multi-matching with the --regex
option, which is not available in older versions:
(setq helm-locate-command "locate %s -e -A --regex %s")
Update: On helm version >=2.4.0 this is now the default.
Execute the helm-locate
command, then enter a filename or pattern at the prompt. Some options are below:
Option | Description |
---|---|
-b | Only use the base name (no directories) |
-e | Only include files that actually exist |
-n | Limit number of search results |
Example pattern:
emacs -b -e -n 12
Note that adding options at end of pattern is disabling fuzzy
matching.
You should add the -b
option at end of other options to let helm
highlight properly the right part (i.e basename) of candidate.
In helm-find-files
, hit C-x C-f
. With a prefix argument, you can choose a locatedb
file.
With two prefix args the database file will be recreated.
When the search is done, you can search in a specific file or directory with the grep
action in the action menu (TAB). You can also launch Helm grep
with (C-u) M-g s
without switching to the action panel.
You can specify a locate
database with prefix argument ARG (C-u
). Many databases can be used: navigate to and mark them. See helm-locate-with-db
.
To create a user specific db, use:
updatedb -l 0 -o dbpath -U directory
where dbpath
is a filename matched by helm-locate-db-file-regexp
.
For this, populate the list helm-locate-project-list
with a list of
projects, then run M-x helm-projects-find-files
, helm-locate
will
search for files only in the database of these projects.
The only thing you have to do is:
(setq helm-locate-fuzzy-match t)
Once this is enabled, helm-locate
will search on the basename of
files, adding automatically the -b
flag, so you don’t need to add
it. As soon as you add spaces between your patterns multi matching
will happen instead of fuzzy, with regexp matching on each pattern
(no fuzzy matching of separate pattern), also when switching to multi
matching, search is done on the whole path and no more on basename.
When fuzzy matching, candidates are sorted with
helm-locate-fuzzy-sort-fn
which use by default the helm fuzzy
matching default sort fn helm-locate-default-fuzzy-sort-fn
, you can
customize this if needed.
On Windows, you should use Everything, which works like locate
. It
is very fast and does not require manual database updates.
To use Everything
with helm-locate
, you will need the command line
tool named es
. Be sure to modify the PATH
environment variable to
include path to the directory that contain es
. Also unset
helm-locate-fuzzy-match
, or Everything
will give no results.
When using es
on Windows, you may want to use the sorting feature
(put the recentest visited files on top) provided by its very last
version (>=es 1.1.0.4a), for this you will have to add here the required arguments to
es
i.e -sort run-count
and also notify the Everything database
you jumped to some file by running es -inc-run-count file
each
time you visit a file, to achieve this you can add a function doing this to
helm-find-many-files-after-hook
.
e.g
(setq helm-locate-command "es %s -sort run-count %s")
(defun helm-es-hook ()
(when (and (equal (assoc-default 'name (helm-get-current-source)) "Locate")
(string-match "\\`es" helm-locate-command))
(mapc (lambda (file)
(call-process "es" nil nil nil
"-inc-run-count" (convert-standard-filename file)))
(helm-marked-candidates))))
(add-hook 'helm-find-many-files-after-hook 'helm-es-hook)
See Topic and issue #1645 on github for more infos.
To use mdfind
, disable helm-locate-fuzzy-match
. If it is set to t
and mdfind
is used, helm-locate
won’t show any results.