4

I'm using Ivy in a fairly standard Spacemacs setup.

When I'm opening a file I'd like . and .. to be omitted from the list of completion candidates. In particular, I'd like to be able to tab through directories with only one entry; right now if I spam TAB in the middle of a long Java path I get a Dired buffer for a directory I don't particularly care about.

E.g., if my current directory is ~/src and I find a file in the following file hierarchy, I'd like C-xC-fjTABTABTABTABBRET to open java/com/example/foo/Bar.java.

ls -R
.:
Makefile java

./java:
com

./java/com:
example

./java/com/example:
foo

./java/com/example/foo:
Bar.java
Quux.java
2
  • 2
    Have you tried setting ivy-extra-directories to nil? See (ivy) File Name Completion.
    – Basil
    Commented Mar 19, 2018 at 22:02
  • @Basil This worked -- please add it as an answer and I will accept.
    – ruds
    Commented Mar 20, 2018 at 12:51

1 Answer 1

7

When I'm opening a file I'd like . and .. to be omitted from the list of completion candidates.

This is what the user option ivy-extra-directories is for:

ivy-extra-directories is a variable defined in ‘ivy.el’.
Its value is ("../" "./")

Documentation:
Add this to the front of the list when completing file names.
Only "./" and "../" apply here.  They appear in reverse order.

In your case, you just need to clear the list:

(setq ivy-extra-directories ())

Quoth (ivy) File Name Completion:

-- User Option: ivy-extra-directories
    Decide if you want to see ‘../’ and ‘./’ during file name
    completion.

    Reason to remove: ‘../’ is the same as ‘DEL’.

    Reason not to remove: navigate anywhere with only ‘C-n’, ‘C-p’ and
    ‘C-j’.

    Likewise, ‘./’ can be removed.

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.