Search code examples
emacskey-bindings

What's the right name for CTL-]?


From my .emacs:

(defun flip-window () "Flip this window" (interactive)
       (switch-to-buffer (other-buffer)))

;; later
(global-set-key [(control ?])] 'flip-window)

It works great, but I have two questions:

  1. is there a built-in function to flip to most recently visited buffer?
  2. While the above works at emacs startup, it causes problems when I'm trying to update settings, there's a parse error caused by the ?]. So is there a better way to express the control-] keystroke?

Solution

  • Answer to the question 2. You may try the kbd function while setting the key binding.

    Like so:

    (global-set-key (kbd "C-]") 'flip-window)
    

    And to the question 1: I guess there is no built in function for that. Emacs redux teaches us to implement it like:

    (defun er-switch-to-previous-buffer ()
      "Switch to previously open buffer. Repeated invocations toggle between the two most recently open buffers."
      (interactive)
      (switch-to-buffer (other-buffer (current-buffer) 1)))
    

    This is part of Emacs Prelude distro. See https://emacsredux.com/blog/2013/04/28/switch-to-previous-buffer/