1

In the linux terminal, i often use wildcards (*) as a shorter alternative to type in the whole file name: if the file is named foo-and-cats I just type in something like fo* in order to pull up the file. This trick also works when i use emacs to pull up a file with C-x C-f, if i use the same trick it finds the file i'm looking for as long as it's in the home folder (i haven't tried files outside the home folder yet...)

However, this trick does not work with pulling up files in the same page buffer: If i type C-x b TUT* it just brings up a new file named TUT* instead of pulling up the tutorial. I have to type the entire file name verbatim in order to get the file i want.

Is there a logical reason why this is so? Is there a way to change this to suite me?

New contributor
thinksinbinary is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • I don't quite understand your question. What function is called with C-f b?
    – aadcg
    Jan 14 at 16:51
  • 2
    You can press TAB to make Emacs complete the buffer name for you. Jan 14 at 16:53
  • @aadcg: C-x b allows you to type in a file name and pull it up within your buffer, so that you don't need anymore emacs windows. For example, if you open a file, you can go back to your last file with by holding control, hitting x, then hitting b seperately. It asks you which file you want to bring up. Jan 14 at 17:03
  • 1
    Ok, it was typo.
    – aadcg
    Jan 14 at 19:16
3

Use of * in a file or directory name is a wildcard for glob matching. (It is unrelated to regular-expression matching, by the way).

Buffer names are not necessarily file names. There are many buffers that are not visiting files. Buffer names sometimes (even often) contain * characters.

Commands that prompt for a buffer name do not do any glob-pattern matching. Commands that prompt for file or directory names often do glob-pattern matching.

1

If you want to type in fewer characters, Emacs has built in completion. You can type a few letters and then hit TAB to complete the input, or to see a list of matching inputs. This can save you a huge amount of time in the long run, and is usually faster than glob or regex matching.

However, it is possible to improve things further. Add this to your init file:

(ido-mode t)
(ido-everywhere 1)

ido-mode will modify all Emacs prompts so that completion is automatic. As you type it will will narrow the available choices until only one remains, and then you can select it by hitting enter. It shows the available choices in the minibuffer even before you hit TAB, so you always know what is available. It provides you with some extra keyboard shortcuts for cycling the list, reversing it, etc, which can all save a lot of typing.

And it’s shipped with Emacs, so you don’t even have to install anything.

Your Answer

thinksinbinary is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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