GNU Emacs Manual - History References

Go to the first, previous, next, last section, table of contents.

#### Shell History References

Various shells including csh and bash support history references that begin with ``!'` and ``^'`. Shell mode can understand these constructs and perform the history substitution for you. If you insert a history reference and type `TAB`, this searches the input history for a matching command, performs substitution if necessary, and places the result in the buffer in place of the history reference. For example, you can fetch the most recent command beginning with ``mv'` with `! m v `TAB``. You can edit the command if you wish, and then resubmit the command to the shell by typing `RET`.

History references take effect only following a shell prompt. The variable `shell-prompt-pattern` specifies how to recognize a shell prompt. Comint modes in general use the variable `comint-prompt-regexp` to specify how to find a prompt; Shell mode uses `shell-prompt-pattern` to set up the local value of `comint-prompt-regexp`.

Shell mode can optionally expand history references in the buffer when you send them to the shell. To request this, set the variable `comint-input-autoexpand` to `input`.

You can make `SPC` perform history expansion by binding `SPC` to the command `comint-magic-space`.

Go to the first, previous, next, last section, table of contents.