【问题标题】:How to switch to a different buffer from a terminal buffer如何从终端缓冲区切换到不同的缓冲区
【发布时间】:2011-01-11 12:22:03
【问题描述】:

我已经使用 emacs 几个星期了,到目前为止一切都很好 - 来自 vim 比我预期的要容易(实际上 - emacs 的键盘快捷键感觉更...自然)。

我添加了一些自定义项,例如使用 M-Left/Right/Up/Down 在缓冲区之间移动,因为当我同时打开四个文件时,C-x o 感觉有点太慢了。

到目前为止 - 非常好:-)

有一件事让我很烦恼:

  1. 我使用C-x 3C-x 2 打开了一些拆分
  2. 我使用M-x term ENT打开其中一个终端
  3. 如何使用键盘切换到不同的拆分?

通常的快捷方式显然不起作用 - 终端正在拦截每个 emacs 命令,我必须单击不同的缓冲区来激活它。

【问题讨论】:

  • 赞成,一个得救的罪人特别欢迎 Emacs 教会。
  • 您应该考虑使用 iswitch-buffer 来更改缓冲区,而不是使用多个窗口。它的生产力要高得多。
  • @NoufalIbrahim 为什么不两者兼而有之?很多时候为了有效地工作,我需要同时查看两个文件或一段代码,两个窗口非常适合。然后icomplete-mode 切换缓冲区(在 24.4 中替换了 iswitch-buffer:emacswiki.org/emacs/IswitchBuffers
  • @ramy 差不多 10 年前我问过这个问题 :-) 这些天我使用 ace-window 包在可见缓冲区之间快速跳转

标签: emacs emacs23


【解决方案1】:

这应该可以让 C-x b 正常工作。您可能必须为任何自定义移动命令添加绑定。

(add-hook 'term-mode-hook
   (lambda ()
     ;; C-x is the prefix command, rather than C-c
     (term-set-escape-char ?\C-x)
     (define-key term-raw-map "\M-y" 'yank-pop)
     (define-key term-raw-map "\M-w" 'kill-ring-save)))

顺便说一句,shell-mode 和 term-mode 之间有很大的区别。前者更好地与 emacs 集成(例如 cd 命令)。后者是一个完整的终端仿真,可以处理诅咒程序。他们都有自己的位置。

【讨论】:

    【解决方案2】:

    对于处理 emacs 窗口的更通用的答案,您可以查看 windmove,我相信它开始与 Emacs 大约在 Emacs 22 中一起发布:

    ;;; Commentary:
    ;;
    ;; This package defines a set of routines, windmove-{left,up,right,
    ;; down}, for selection of windows in a frame geometrically.  For
    ;; example, `windmove-right' selects the window immediately to the
    ;; right of the currently-selected one.  This functionality is similar
    ;; to the window-selection controls of the BRIEF editor of yore.
    ;;
    ;; One subtle point is what happens when the window to the right has
    ;; been split vertically; for example, consider a call to
    ;; `windmove-right' in this setup:
    ;;
    ;;                    -------------
    ;;                    |      | A  |
    ;;                    |      |    |
    ;;                    |      |-----
    ;;                    | *    |    |    (* is point in the currently
    ;;                    |      | B  |     selected window)
    ;;                    |      |    |
    ;;                    -------------
    ;;
    ;; There are (at least) three reasonable things to do:
    ;; (1) Always move to the window to the right of the top edge of the
    ;;     selected window; in this case, this policy selects A.
    ;; (2) Always move to the window to the right of the bottom edge of
    ;;     the selected window; in this case, this policy selects B.
    ;; (3) Move to the window to the right of point in the selected
    ;;     window.  This may select either A or B, depending on the
    ;;     position of point; in the illustrated example, it would select
    ;;     B.
    ;;
    ;; Similar issues arise for all the movement functions.  Windmove
    ;; resolves this problem by allowing the user to specify behavior
    ;; through a prefix argument.  The cases are thus:
    ;; * if no argument is given to the movement functions, or the
    ;;   argument given is zero, movement is relative to point;
    ;; * if a positive argument is given, movement is relative to the top
    ;;   or left edge of the selected window, depending on whether the
    ;;   movement is to be horizontal or vertical;
    ;; * if a negative argument is given, movement is relative to the
    ;;   bottom or right edge of the selected window, depending on whether
    ;;   the movement is to be horizontal or vertical.
    

    【讨论】:

      【解决方案3】:

      在术语模式下,键入C-c b RET 以切换到其他缓冲区。

      这和 C-x b RET 通常做的一样。

      【讨论】:

        【解决方案4】:

        在术语模式下,任何常规的C-x whatever 键绑定都会变为C-c whatever

        【讨论】:

        • 这应该会得到更多的支持 - 有时需要 mx term 和 mx shell 之间的差异 - 例如,使用 watch 命令来关注数据的变化(除非有更好的 emacs方法)。
        • 非常正确,我目前的问题是我已经将窗口切换到 C-f/b/n/p,但是当我在学期时,我无法切换出去!
        • 有谁知道为什么会这样?为什么不像往常一样使用 C-x(stty -a 命令不显示 C-x 的绑定)。
        • 为反对票道歉。我误读了答案,并认为这是错误的。不幸的是,我意识到为时已晚,反对票现已锁定。
        【解决方案5】:

        我不确定我是否理解您的问题。如果你运行 Mx terminal,大部分关键事件都会发送到底层终端,所以标准的 Cx o 绑定和你的 M-Left在终端中不可用。

        尝试使用 M-x shell 在其中一个窗口中获取 shell,您设置的导航绑定应该仍然有效。

        【讨论】:

        • 谢谢 - 这解决了我的问题。不知道 M-x shell 和 M-x term 有区别。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-20
        • 1970-01-01
        • 1970-01-01
        • 2019-01-09
        • 2011-10-12
        相关资源
        最近更新 更多