modeller
modeller

Reputation: 3850

How to go to beginning of command in term mode in Emacs?

I am running bash terminal under Term: line run mode inside Emacs.

Often I want to go to beginning of a command (not beginning of line, which includes the prompt). i.e. In below line, I 'd like to go to s (not p).

prompt> some command text here

May I know what is the key shortcut in doing so, if any?

Upvotes: 0

Views: 579

Answers (1)

phils
phils

Reputation: 73256

C-cC-a (term-bol) is intended to do this. It works by moving to the beginning of the line, and then skipping forward past the prompt, as defined by the buffer-local term-prompt-regexp variable.

However the default value for that regex is just ^ (which therefore has no effect in this situation); so you would need to set it yourself. There are some useful examples in that variable's help text.

Some alternative options are:

  • Use term-char-mode instead (in which case C-a works).
    You can switch to char mode with C-cC-k and back to line mode with C-cC-j.
  • Copy that same binding for C-a for term-line-mode, so that it does the same thing in both modes:

    (define-key term-mode-map (kbd "C-a") 'term-send-raw)
    
  • Create a new binding which does the same thing. e.g.:

    (define-key term-mode-map (kbd "s-a") (lambda () (interactive) (term-send-raw-string (string 1))))
    

    n.b. Using (string 1) because C-a is ascii value 1. See the definition of term-send-raw.

Upvotes: 2

Related Questions