Post

27 Shell mode commands

If you want to run another particular shell (for example, the zed shell) when you’re in Emacs, you can add the following command to your .emacs file:

1
(setq shell-file-name "/bin/zsh")

When Emacs starts an interactive shell, it runs an additional initialization file after your shell’s normal startup files. The name of this file is .emacs_shell-name, where shell-name is the name of the shell you want to use in Emacs. It must be located in your home directory. For example, if you use the C shell, you can add Emacs-only startup commands by placing them in the file .emacs_csh. Let’s say that when you’re in Emacs, you want to change the prompt to emacs:% and you want an environment variable called WITHIN_EDITOR to be set to T. Here’s the contents of your .emacs_csh file:

1
2
set prompt="emacs:% "
setenv WITHIN_EDITOR T

Within a shell buffer, Emacs also sets the environment variable EMACS to t, and sets your terminal type (the TERM variable) to emacs.

KeystrokesCommand nameAction
(none)shellEnter shell mode.
C-c C-c Signals BREAKcomint-interrupt-subjobInterrupt current job; equivalent toC-c.
C-dcomint-delchar-or-maybe-eofSend EOF character if at end of buffer; delete a character elsewhere.
C-c C-d Signals EOFcomint-send-eofSend EOF character.
C-c C-ucomint-kill-inputErase current line; equivalent toC-u in Unix shells.
C-c C-z Signals STOPcomint-stop-subjobSuspend or stop a job;C-z in Unix shells.
M-p In/Out Previous Inputcomint-previous-inputRetrieve previous commands (can be repeated to find earlier commands).
M-n In/Out Next Inputcomint-next-inputRetrieve subsequent commands (can be repeated to find more recent commands).
Entercomint-send-inputSend input on current line.
Tabcomint-dynamic-completeComplete current command, filename, or variable name.
C-c C-o In/Out Delete Current Output Groupcomint-kill-outputDelete output from last command.
C-c C-rcomint-show-outputMove first line of output to top of window.
C-c C-e In/Out Show Maximum Outputcomint-show-maximum-outputMove last line of output to bottom of window.
C-c C-p In/Out Backward Output Groupcomint-previous-promptMove to previous command.
C-c C-n In/Out Forward Output Groupcomint-next-promptMove to next command.
This post is licensed under CC BY 4.0 by the author.