* {{Keys|M-r}} search backward a regexp in commands' history (like C-r in term). Use C-r to cycle.

* {{Keys|C-c r}} go to beginning of output (useful when you have a large output and want to read through the beginning)

* {{Keys|C-c r}} go to beginning of output (useful when you have a large output and want to read through the beginning)

* {{Keys|C-c-p}} go to beginning of previous output group

* {{Keys|C-c-p}} go to beginning of previous output group

* {{Keys|C-c-c}} send the '''C-c''' command to the shell

* {{Keys|C-c-c}} send the '''C-c''' command to the shell

−

* {{Keys|C-c-o}} delete the output of last command

+

* {{Keys|C-c-o}} delete the output of the last command

+

+

To launch a shell in the directory of the current buffer, have a look to '''shell-here''': https://github.com/ieure/shell-here (available through ELPA).

+

+

== re-execute successive commands ==

−

To launch a shell in the current buffer, have a look to '''shell-here''': https://github.com/ieure/shell-here (available through ELPA).

+

Often it is useful to reexecute several successive shell commands that were previously executed in sequence. To do this, first find and reexecute the first command of the sequence. Then type {{Keys|C-c C-x}}, that will fetch the following command--the one that follows the command you just repeated. Then type RET to reexecute this command. You can reexecute several successive commands by typing {{Keys|C-c C-x RET}} over and over.

= Customisation =

= Customisation =

Line 45:

Line 52:

(add-hook 'shell-mode-hook 'compilation-shell-minor-mode)

(add-hook 'shell-mode-hook 'compilation-shell-minor-mode)

+

Now you can use key bindings from the mode: use {{CommandKeys|C-x `|next-error}} (backquote) to go to the next error detected in the shell. You can't do that in an xterm !

+

+

== Change directory with ido-mode ==

+

+

Using [[ido]]'s completion system for changing directories is a big gain in usability and efficiency for emacs' shell. I urge you to check this Stack Overflow question: http://stackoverflow.com/questions/20952995/emacs-shell-change-directory-with-ido

+

+

== Shared and persistent history ==

+

+

By default a shell session inside emacs via '''shell-mode''' won't persist accross sessions and won't read your shell's history. The '''history''' shell command works as expected, but you can't search (with '''M-r''') a command that you typed in shell-mode in another emacs instance or in a term. The following fixes that.

+

+

For '''comint-mode''' and derivatives (including '''shell-mode''') the searchable history is read in via '''comint-read-input-ring''', which uses '''comint-input-ring-file-name''' which you can set in a mode hook. However I would suggest that you actually set your HISTFILE environment variable to ~/.zsh_history because shell-mode automatically defers to that.

Note that if you want to persist more variables (mini-buffer history,…), enable '''savehist-mode''' and configure the variables you wish to persist between sessions. See {{Command|customize-group RET savehist RET}}.

= See also =

= See also =

Revision as of 11:04, 15 April 2014

Shell-mode gives access to a shell in a normal emacs buffer, meaning you can move around and edit it as usual. A drawback is that you can not launch programs like htop or other ncurses ones, like you would in term-mode.

re-execute successive commands

Often it is useful to reexecute several successive shell commands that were previously executed in sequence. To do this, first find and reexecute the first command of the sequence. Then type [C-c C-x], that will fetch the following command--the one that follows the command you just repeated. Then type RET to reexecute this command. You can reexecute several successive commands by typing [C-c C-x RET] over and over.

Make URLs clikable

(add-hook 'shell-mode-hook (lambda () (goto-address-mode )))

Make file paths clickable

Every line representing a path to a file will be colorized and made clickable, so that you can jump to that file and that line, like in compilation-mode (specially useful when compiling a program or running tests):

(add-hook 'shell-mode-hook 'compilation-shell-minor-mode)

Now you can use key bindings from the mode: use [C-x `] (or M-x next-error) (backquote) to go to the next error detected in the shell. You can't do that in an xterm !

Shared and persistent history

By default a shell session inside emacs via shell-mode won't persist accross sessions and won't read your shell's history. The history shell command works as expected, but you can't search (with M-r) a command that you typed in shell-mode in another emacs instance or in a term. The following fixes that.

For comint-mode and derivatives (including shell-mode) the searchable history is read in via comint-read-input-ring, which uses comint-input-ring-file-name which you can set in a mode hook. However I would suggest that you actually set your HISTFILE environment variable to ~/.zsh_history because shell-mode automatically defers to that.

Note that if you want to persist more variables (mini-buffer history,…), enable savehist-mode and configure the variables you wish to persist between sessions. See M-x customize-group RET savehist RET.

See also

shell-pop to pop up and pop out a shell buffer window easily (installable via ELPA).