38

When using ido-mode in emacs, it tends to get in my way when I'm trying to create a new file inside a directory, using: C-x C-f ( start typing a new filename, which doesn't yet exist ) RET

Ordinarily this should create a new file, but when I have ido mode, I have to type the new filename really quickly, otherwise ido-mode decides to move me into a directory that has a file with a matching name, causing me to open that file, instead of creating a new file.

Does anybody know how to force ido-mode to avoid looking in directories other than the one you're currently in?

d11wtq
  • 34,788
  • 19
  • 120
  • 195

3 Answers3

38

You can disable the merging (the "looking in other directories" in ido vulgo) with

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

but you can also undo the merge with C-z in ido.

Michael Markert
  • 3,986
  • 2
  • 19
  • 19
  • 2
    Right you are :) I would not have guessed the purpose from the name of that function. Works perfectly. – d11wtq Sep 20 '11 at 15:54
  • 3
    Thanks, I wasn't clear what the heck "merge" meant in the `ido` context until I found this answer. – Brighid McDonnell Sep 08 '12 at 23:32
  • `C-z` gets me what I need (I was having the exact same problem); thanks! This way I can keep the behavior (it's convenient, *sometimes*), but still have a way to get out of it when it's not what I want (most of the time). – lindes Dec 21 '13 at 21:23
  • "it's convenient, sometimes" you can also disable it and trigger the merge using M-s if that is what you would prefer (I do). – graywolf Aug 03 '23 at 18:52
27

Doing this really helps. Basically use ido-mode up until you get to the correct directory, then hit C-f again to get out of ido-mode as you type the new filename.

C-x C-f navigate to directory C-f enter new filename RET.

d11wtq
  • 34,788
  • 19
  • 120
  • 195
  • I have a feeling this should have more up-votes than the other answer. thx –  Oct 16 '15 at 23:22
4

Use C-j to tell ido to input what you have typed rather than the first completion. This is also mentioned on emacswiki.

Ross Patterson
  • 5,702
  • 20
  • 38
  • 4
    This only works if you've finished typing the filename before it switches directory. If I've stalled halfway through typing a filename, it switches directory, then when I carry on typing, it's just matching files in some other part of my home directory. – d11wtq Sep 20 '11 at 03:38
  • 2
    Hmm, actually, just double typing C-x C-f C-f if my plan is to create a new file seems to help, since that jumps out of ido mode. It's not perfect, but it's better than it changing directory. – d11wtq Sep 20 '11 at 03:40