Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use tcsh, and I'd like to set up the following behaviour, which I've seen on some systems in the past. If I type

!string TAB


  • If the history contains a unique entry beginning with string, autocompletion should take place, and I can edit the resulting command, or just press return to execute it.

  • If the history contains multiple entries beginning with string, a list of possible completions is displayed, the command is partially completed as far as possible (without eliminating any possibilities from the list), and on the command line I should have an exclamation mark followed by the partially completed command, so that I can type more characters and press TAB again.

How do I achieve this?

share|improve this question
up vote 1 down vote accepted


set autoexpand

to .tcshrc to activate this feature.

share|improve this answer

Probably, you are searching for history-search-backward and history-search-forward editor commands.

As default, these commands are binded to M-p (usually alt+p on pc keyboards) and M-n (alt+n).

You can re-bind them to any other key sequence using bindkey command. E.g.:

 bindkey '\t' history-search-backward

Note that you do not need to place a ! at line beginning to use these commands.

share|improve this answer
No, that's something different. – Ian Thompson Aug 24 '11 at 9:31
@infoclogged thank you, I fixed the typo in the example – andcoz Jun 24 '15 at 12:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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