简体   繁体   中英

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). ie 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?

Cc Ca ( 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 Ca works).
    You can switch to char mode with Cc Ck and back to line mode with Cc Cj .
  • Copy that same binding for Ca for term-line-mode , so that it does the same thing in both modes:

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

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

    nb Using (string 1) because Ca is ascii value 1. See the definition of term-send-raw .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM