有没有一种方法可以在不通过缓冲区列表或写出要切换到的缓冲区名称的情况下切换缓冲区?更具体地说,我想知道Emacs是否可以像Notepad ++中那样使用选项卡在缓冲区之间切换
有没有一种方法可以在不通过缓冲区列表或写出要切换到的缓冲区名称的情况下切换缓冲区?更具体地说,我想知道Emacs是否可以像Notepad ++中那样使用选项卡在缓冲区之间切换
next/previous-buffer
命令的话。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)
我自己使用 Icicles 进行缓冲区切换,但是...
如果你想重复上一个命令多次,只需使用 C-x z z z z z z... 例如,在这种情况下,你可以使用 C-x left C-x z z z...
如果这太麻烦了,像其他人建议的那样将 (next|previous)-buffer
绑定到其他可重复按键上。
但是可重复的按键非常受欢迎。如果你不想浪费任何按键,甚至可以将这些命令放在一个前缀键上,这样,例如,你可以做,例如,C-x left left left... 这里有一个从Bookmark+代码中提取出来的技巧:
(defun my-repeat-command (command) "重复执行 COMMAND." (let ((repeat-message-function 'ignore)) (setq last-repeatable-command command) (repeat nil)))Ctrl-TAB
方式。当然,这些命令可以根据个人配置进行调整(纯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)
(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
找到要使用的键序列。
实际上,在释放<C-tab>
后,仍然需要按下RET
或C-l
。
对于使用Helm的Evil用户,一种可能更好的选择是将helm-buffers-list
绑定到C-j
和C-k
,然后将helm-follow-mode-persistent
设置为t
,并在helm-buffers-list
缓冲区中使用C-c C-f
激活helm-follow-mode
。现在,您可以使用C-j
和C-k
切换(和预览)缓冲区。