缓冲区之间的Emacs选项卡

时间:2010-11-09 11:32:50

标签: emacs elisp

有没有办法在缓冲区之间切换而无需经过 buffer-list,还是写下我要切换到的缓冲区的名称?更具体的是我想知道emacs是否可以在缓冲区之间进行选项,就像它在notepad ++中的工作方式一样

4 个答案:

答案 0 :(得分:4)

Emacs 22.1及更高supports previous-bufferC-x <left arrow>)和next-bufferC-x <right arrow>)命令。

可以使用this script将这两个命令添加到旧版Emacsen中。

答案 1 :(得分:3)

我从来没有最终使用 Cx&lt; right&gt; Cx&lt; C-right&gt; ,因为我发现如果我想要重复它们很麻烦循环经过多个缓冲区,所以我刚写了几个函数让你继续用&lt; C-right&gt; &lt; C切换到next/previous-buffer -left&gt; 如果最后一个命令也是next/previous-buffer命令。

e.g。 C-x&lt; C-left&gt; c为C-左&GT; c为C-左&GT; c为C-右&GT; &lt; C-left&gt; 将带你回三个缓冲区,前进一个,然后再向后。

我假设&lt; C-left&gt; &amp; &lt; C-right&gt; 通常绑定到forward/backward-word,并且明确地将其称为后备。

(defun my-forward-word-or-buffer-or-windows (&optional arg)
  "Enable <C-left> to call next-buffer if the last command was
next-buffer or previous-buffer, and winner-redo if the last
command was winner-undo or winner-redo."
  (interactive "p")
  (cond ((memq last-command (list 'next-buffer 'previous-buffer))
         (progn (next-buffer)
                (setq this-command 'next-buffer)))
        ((memq last-command (list 'winner-redo 'winner-undo))
         (progn (winner-redo)
                (setq this-command 'winner-redo)))
        (t ;else
         (progn (forward-word arg)
                (setq this-command 'forward-word)))))

(defun my-backward-word-or-buffer-or-windows (&optional arg)
  "Enable <C-left> to call previous-buffer if the last command
was next-buffer or previous-buffer, and winner-undo if the last
command was winner-undo or winner-redo."
  (interactive "p")
  (cond ((memq last-command (list 'next-buffer 'previous-buffer))
         (progn (previous-buffer)
                (setq this-command 'previous-buffer)))
        ((memq last-command (list 'winner-redo 'winner-undo))
         (progn (winner-undo)
                (setq this-command 'winner-undo)))
        (t ;else
         (progn (backward-word arg)
                (setq this-command 'backward-word)))))

(global-set-key (kbd "<C-left>") 'my-backward-word-or-buffer-or-windows)
(global-set-key (kbd "<C-right>") 'my-forward-word-or-buffer-or-windows)

答案 2 :(得分:1)

(我使用 Icicles 进行缓冲切换,我自己,但是......)

如果你想多次重复上一个命令,只需使用 Cx zzzzzz ...在这种情况下,例如, Cx离开Cx zzz ...

如果这太麻烦,请将(next|previous)-buffer绑定到其他可重复的键,就像其他人建议的那样。

但可重复的按键需求很大。如果您不想浪费任何东西,您甚至可以将这些命令放在前缀键上,这样,例如,您可以这样做,例如, Cx左左 ...这是一个技巧这样做(取自 Bookmark+ 代码):


    (defun my-repeat-command (command)
      "Repeat COMMAND."
      (let ((repeat-message-function  'ignore))
        (setq last-repeatable-command  command)
        (repeat nil)))

    (defun my-next-whatever-repeat (arg)  ; `C-x right'
      "Jump to the Nth-next whatever.
    N defaults to 1, meaning the next whatever.
    Plain `C-u' means start over at the first whatever (and no repeat)."
      (interactive "P")
      (require 'repeat)
      (my-repeat-command 'next-whatever))

    (define-key ctl-x-map [right] 'my-next-whatever-repeat 

答案 3 :(得分:1)

尽管以下建议确实使用了缓冲区列表、Ivy(或 Helm)和 evil,但我认为它是一种不错的、几乎等效的替代常见的 Ctrl-TAB 方式(包括更新缓冲区列表)使用例如太空麦克斯。 当然这些命令可以适应你的个人配置(vanilla Emacs)

(evil-global-set-key 'motion (kbd "<C-tab>") 'ivy-switch-buffer)
(evil-global-set-key 'insert (kbd "<C-iso-lefttab>") 'ivy-switch-buffer)
(define-key ivy-mode-map (kbd "<C-tab>") 'ivy-next-line-and-call)
(define-key ivy-mode-map (kbd "<C-iso-lefttab>") 'ivy-previous-line-and-call)

或 Helm 的等价物

(evil-global-set-key 'motion (kbd "<C-tab>") 'helm-buffers-list)
(evil-global-set-key 'motion (kbd "<C-iso-lefttab>") 'helm-buffers-list)
(define-key helm-map (kbd "<C-tab>") 'helm-follow-action-forward)
(define-key helm-map (kbd "<C-iso-lefttab>") 'helm-follow-action-backward)

最后一个命令的键串在我的键盘中表示 Ctrl-Shift-tab。您可以找到与 C-h k C-S-tab 一起使用的那个。

确实在释放RET后您仍然需要按C-l<C-tab>

对于使用 Helm 的恶意用户,一个可能更好的选择是将 helm-buffers-list 绑定到 C-jC-k,然后将 helm-follow-mode-persistent 设置为 t,并且在 helm-buffers-list 缓冲区中使用 helm-follow-mode 激活 C-c C-f。现在您可以使用 C-jC-k 切换(和预览)缓冲区。