When i want to create a new file with C-x C-f (ido-find-file), and type main.lua, Emacs does not create a new file in the current directory (default-directory). Instead, it visits an existing main.lua which is in another directory.

Similarly when I want to create a new directory src, instead of creating a new directory Emacs visits a src directory in another project.

This means I can never create a new file or a new directory.

I've installed the package tree-emacs. I have the same problem when I right-click a tree-emacs buffer and try to create a new file or a new directory - Emacs visits an existing file or directory which I do not want.

How can I stop Emacs from looking outside the current directory for an existing file or dir, instead of creating a buffer for a new one in the current directory?

  • To which command is your C-x C-f bound? You can tell it with C-h k C-x C-f.
    – Marioba
    Jan 29, 2021 at 9:06
  • "C-x C-f runs the command ido-find-file, which is an interactive autoloaded compiled Lisp function in ‘ido.el’. It is bound to <open>, C-x C-f, <menu-bar> <file> <new-file>. (ido-find-file)" Jan 29, 2021 at 10:52

1 Answer 1


If you're using Ido, you can hit C-f whenever you want to fall back to regular find-file, thus preventing Ido from doing fancy things. If you want to disable the feature that lets Ido retrieve files from subdirectories for good, add

(setq ido-auto-merge-work-directories-length -1)

to your init file. Then you can always use M-s to invoke it manually.

  • it works thanks a lot. Jan 29, 2021 at 11:03
  • Or you could disable ido-find-file completely but continue to use ido: (define-key (cdr ido-minor-mode-map-entry) [remap find-file] nil)
    – Edman
    Jan 29, 2021 at 11:26
  • @olegharput: if the answer works for you, please accept it.
    – NickD
    Jan 29, 2021 at 13:50
  • I was about to say that. I guessed that some completion package might be interfering. Jan 29, 2021 at 15:49
  • If this answers the question, you might want to accept this answer. (Or you might want to wait a while, to see if you get another answer that you prefer.)
    – Drew
    Jan 29, 2021 at 17:37

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.