简体   繁体   English

如何在Emacs中的术语模式下转到命令开头?

[英]How to go to beginning of command in term mode in Emacs?

I am running bash terminal under Term: line run mode inside Emacs. 我正在Emacs中的Term: line run mode下运行bash终端。

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 ). 即在下面的行中,我想转到s (而不是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. Cc Caterm-bol )旨在实现这一目的。 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. 它的工作方式是移至该行的开头,然后向前跳过提示,如缓冲区本地term-prompt-regexp变量所定义。

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). 请改用term-char-mode (在这种情况下, Ca起作用)。
    You can switch to char mode with Cc Ck and back to line mode with Cc Cj . 您可以使用Cc Ck切换到char模式,使用Cc Cj切换回行模式。
  • Copy that same binding for Ca for term-line-mode , so that it does the same thing in both modes: term-line-mode复制Ca的相同绑定,以便在两种模式下都执行相同的操作:

     (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 . nb使用(string 1)因为Ca是ascii值1。请参见term-send-raw的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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