如何从终端缓冲区切换到不同的缓冲区

发布于 2024-08-20 06:33:45 字数 454 浏览 13 评论 0原文

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

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

到目前为止 - 很好:-)

不过有一件事让我烦恼:

  1. 我使用 Cx 3Cx 2 打开一些拆分,
  2. 我使用 在其中一个拆分中打开终端Mx term ENT
  3. 如何使用键盘切换到不同的分割?

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

I've been using emacs for few weeks and it's been great so far - coming from vim was easier than I expected (actually - emacs' keyboard shortcuts feel more... natural).

I have added few customizations like moving between buffers using M-Left/Right/Up/Down because C-x o felt a little bit too slow when I had four files opened at once.

So far - so good :-)

One thing bugs me though:

  1. I open some splits using C-x 3 and C-x 2
  2. I open the terminal in one of them using M-x term ENT
  3. How do I switch to different split using keyboard?

Usual shortcuts obviously don't work - terminal is intercepting every emacs command, and I have to click on different buffer to activate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

煞人兵器 2024-08-27 06:33:45

在术语模式下,任何常规的Cxwhatever键绑定都会变成Ccwhatever

In term-mode, any regular C-x whatever keybinding becomes C-c whatever instead.

银河中√捞星星 2024-08-27 06:33:45

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

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

I'm not sure I understand your question. If you run M-x terminal, most of the key events are sent to the underlying terminal, so the standard C-x o binding and your M-Left are not available in the terminal.

Try using M-x shell to get a shell in one of the windows, and the navigation bindings you set up should still work.

悲凉≈ 2024-08-27 06:33:45

在 term-mode 中,输入 Cc b RET 切换到其他缓冲区。

这与 Cx b RET 通常的作用相同。

In term-mode, type C-c b RET to switch to some other buffer.

That does what C-x b RET normally does.

↘人皮目录ツ 2024-08-27 06:33:45

这应该可以让 Cx 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 模式和 term 模式之间有很大的区别。前者与 emacs 集成得更好(例如 cd 命令)。后者是一个完整的终端仿真,可以处理curses程序。他们都有自己的位置。

This should do the trick to get C-x b working. You may have to add bindings for any custom move commands.

(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)))

BTW, there is a big difference between shell-mode and term-mode. The former integrates better with emacs (e.g. cd command). The latter is a full terminal emulation and can handle curses programs. They both have their place.

梦断已成空 2024-08-27 06:33:45

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

;;; 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.

For a more generic answer dealing with emacs' windows, you can look at windmove, which started shipping with Emacs circa Emacs 22, I believe:

;;; 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文