4

I am new to emacs (using Spacemacs with Evil and Ivy). This is how I open a file: SPC f f (counsel-find-file)

Find file:

I entered path of file. Ivy matches words one directory at a time. But drilling down is getting tiresome.

Is there a way Ivy can look into a directory to match file names a few levels down?

5
  • 1
    Have you tried counsel-file-jump? Commented Jun 24, 2017 at 13:03
  • If you find counsel-file-jump useful and are running a Un*x OS, you may also like to try the built-in command locate and its counsel counterpart, counsel-locate, though these are a bit more scattergun than the former.
    – Basil
    Commented Jun 24, 2017 at 13:55
  • counsel-file-jump by default completes files only under the current default-directory. Are you sure you are in the expected parent directory before invoking it? Alternatively, the command prompts the user for a different directory when invoked with a prefix argument.
    – Basil
    Commented Jun 25, 2017 at 17:01
  • (ivy-read "File: " (directory-files-recursively default-directory "")) starts an ivy completion session with all files under the current default-directory (I modified the code slightly to make it more idiomatic). As it stands, however, it will merely return the selected completion candidate and not actually read any files. I recommend reading the Ivy Manual for more information.
    – Basil
    Commented Jun 25, 2017 at 17:05
  • Thanks @Basil, counsel-file-jump works as advertised if I first use counsel-find-file or neotree to select a parent directory. Not sure what I was doing before.
    – wolfv
    Commented Jun 26, 2017 at 18:03

3 Answers 3

3

Two ways to find a file name deep in a directory, without having to drill down:

SPC SPC counsel-file-jump lists all files below parent directory. But first use SPC f f (counsel-find-file) to select a parent directory.

SPC f L (counsel-locate) lists all matching directory and file names from Linux root.

2

Don't know about ivy, but at least the default completion in Emacs lets you do that if you know how many levels down you want to go:

C-x C-f */*/filena TAB

will look for files whose name starts with filena 2 levels down from where you are. I've had a todo-item to add support for ** for many years now. Hopefully someone will beat me to it.

1

If you use Icicles then you can match any parts of an absolute file name. It doesn't matter how deep the file is, and there is no need to know how deep it is.

If you have files with the same name at different parts of the file system then you can match some part(s) of their ancestor directories. If you don't then, if you want, you can match just the (leaf) relative file name itself.

See File-Name Input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.