The correct way to ignore files by extension for file name completion purposes is using the variable
completion-ignored-extensions. The variable holds a list of strict suffix strings that are ignored for:
- directory completion, if the list element ends in a
- file completion otherwise.
ido-ignore-files variable, on the other hand, is a list of regular expressions, and matches anywhere in the file name, unless the regex is anchored. In particular, the recommendation in another answer,
(add-to-list 'ido-ignore-files "\.bak")
tells Ido to match the substring
.bak anywhere in file name, which may or may not be what you really want. On the other hand,
(add-to-list 'completion-ignored-extensions ".bak")
makes all Emacs completion machinery, not only Ido, but also out-of-the-box file completion and Dired, and likely other places, ignore files ending in
.bak (including full name match). Note that this variable is not a list of regexes, but rather a list of literal suffixes; the dot should not be
completion-ignored-extensions list contains commonly ignored suffixes such as
.git/, and many more. This is why the default
ido-ignore-files list is suspiciously short.
The completion behavior is actually more complex than just always ignoring the files; see the docstring of the variable. One important point is that if all completions are to be ignored according to
completion-ignored-extensions, then none are. This allows, for example, descending into the
.git/ subdirectory: as soon as it becomes the only completion (after typing
.g/, if no other directories matching
.g*/ exist), it is shown by Ido as a possible completion. Similarly, in the original question case, typing
.bak makes Emacs "un-ignore" and immediately show files ending in
.bak, unless other non-ignored files match by Ido rules, so that the C-a is not always necessary to find an ignored file.