Emacs - Python 使用部分键入的命令在劣质 shell 中完成

Emacs - Python completion in inferior shell with partially typed command

我经常在 ipython shell 中使用的一个功能是从历史记录中自动完成部分键入的命令。在 repl,可以只键入命令的前几个字母并点击 up 以在命令历史记录中查找以部分键入的字符串开头的最后执行的命令。

emacs 中是否提供此功能?按C-up,可以调用python命令历史,但它不使用部分键入的命令?

您可以使用 comint-previous-matching-input-from-inputcomint-next-matching-input-from-input 完成部分键入的命令。

默认绑定到 C-c M-rC-c M-s.

如果您输入了 l = 1,现在您可以输入 l 并按 C-c M-r 来完成之前的操作。

如果您不想使用 C-c M-r 而喜欢使用向上箭头,请将此代码放入您的配置中。

(eval-after-load 'comint
    '(progn      
         (define-key comint-mode-map (kbd "<up>") 
            #'comint-previous-matching-input-from-input)
         (define-key comint-mode-map (kbd "<down>")
            #'comint-next-matching-input-from-input)))

现在您可以使用 向上/向下 箭头。