2

I installed Emacs via homebrew using this Emacs bundle, https://github.com/railwaycat/homebrew-emacsmacport

This bundle has some nice OS X features but it doesn't have the OS X keyboard shortcuts enabled by default (e.g., command + c for copy and command + v for paste). How can I enable this? I would have thought a Google search would find the answer but all I found was this https://www.emacswiki.org/emacs/MacKeyMode but I am not sure if that's still relevant.

Any pointers would be welcomed and sorry if I missed something obvious.

2
  • Welcome! I think you may be looking for cua-mode ("Common User Access" mode, so you can use some standard keybindings for cut and paste).
    – Dan
    Dec 11 '20 at 19:50
  • 1
    Thanks for the quick reply, Dan. That works for ctrl+c and ctrl+v and so on, but I'd like to use the command+c and command+v keys and that doesn't seem to do the trick.
    – cdd
    Dec 11 '20 at 20:10
3

You could add any (or all) of the following key bindings to your init.el to have most of the key commands working as a macOS user would expect...

(setq mac-option-modifier 'meta          
      mac-command-modifier 'super 
      mac-right-option-modifier 'none)) 

  (global-set-key (kbd "s-c") 'kill-ring-save)
  (global-set-key (kbd "s-v") 'yank)
  (global-set-key (kbd "s-x") 'kill-region)
  (global-set-key (kbd "s-a") 'mark-whole-buffer)
  (global-set-key (kbd "s-z") 'undo)
  (global-set-key (kbd "s-f") 'isearch-forward)
  (global-set-key (kbd "s-g") 'isearch-repeat-forward)
  (global-set-key (kbd "s-o") 'find-file)
  (global-set-key (kbd "s-o") 'mac-open-file)
  (global-set-key (kbd "s-n") 'find-file)
  (global-set-key (kbd "s-s") 'save-buffer)
  (global-set-key (kbd "s-S") 'mac-save-file-as) 
  (global-set-key (kbd "s-p") 'mac-preview) ; requires mac-preview
  (global-set-key (kbd "s-w") 'kill-buffer)
  (global-set-key (kbd "s-m") 'iconify-frame)
  (global-set-key (kbd "s-q") 'save-buffers-kill-emacs)
  (global-set-key (kbd "s-.") 'keyboard-quit)
  (global-set-key (kbd "s-l") 'goto-line)
  (global-set-key (kbd "s-k") 'kill-buffer)
  (global-set-key (kbd "s-<up>")    'beginning-of-buffer)
  (global-set-key (kbd "s-<down>")  'end-of-buffer)
  (global-set-key (kbd "s-<left>")  'beginning-of-line)
  (global-set-key (kbd "s-<right>") 'end-of-line)
  (global-set-key [(meta down)]     'forward-paragraph)
  (global-set-key [(meta up)]       'backward-paragraph)

For a mac like open & save interface you might also need these applescript wrappers...

  (defun mac-open-file ()
    (interactive)
    (let ((file (do-applescript "POSIX path of (choose file)")))
      (if (> (length file) 3)
          (setq file
                (substring file 1 (- (length file) 1))))
      (if (and (not (equal file "")) (file-readable-p file))
          (find-file file))))

  (defun mac-save-file-as ()
    (interactive)
    (let ((file (do-applescript "POSIX path of (choose file name with prompt \"Save As...\")")))
      (if (> (length file) 3)
          (setq file
                (substring file 1 (- (length file) 1))))
      (if (not (equal file ""))
          (write-file file))))

the key map is based on the following...

    ⌘ + O — Open an existing file into an Emacs buffer
    ⌘ + W — Discard (kill) current buffer
    ⌘ + S — Save current buffer into its file
    ⌘ + ⇧ (Shift) + S — Write current buffer into another file
    ⌘ + I — Display current file/directory in a Finder window
    ⌘ + P — Print current buffer
    ⌘ + Q — Quit
    ⌘ + Z — Undo
    ⌘ + ⇧ (Shift) + Z — Redo
    ⌘ + X — Cut
    ⌘ + C — Copy
    ⌘ + V — Paste
    ⌘ + A — Select All
    ⌘ + F — Search for a string
    ⌘ + ⌥ (Option) + F — Advanced Search (M-x occur)
    ⌘ + G — Search forward for a string
    ⌘ + ⇧ (Shift) + G — Search backward for a string
    ⌘ + L — Go to Line
    ⌘ + T — Show/Hide the font panel
    ⌘ + M — Minimize the window
    ⌘ + ` — Move to a different visible window (frame)
    ⌘ + ⇧ (Shift) + N — Make a new window (frame)
    ⌘ + ⇧ (Shift) + W — Close window (frame)
    ⌘ + ? — Show help files (M-x info)
    ⌘ + / — Same as ⌘ + ?
    ⌘ + . — Interrupt operation
    ⌘ + ↑ — Move point to the beginning of the buffer
    ⌘ + ↓ — Move point to the end of the buffer
    ⌘ + ← — Move point to beginning of current line
    ⌘ + → — Move point to end of current line
    ⌘ + Click — Open URL with a browser
    ⌃ (Control) + Click — Show contextual menu
    ⇧ (Shift) + Click — Select region

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.