0

I use Emacs on MacOS, installed by homebrew:

% ls -l /opt/homebrew/bin/emacs
lrwxr-xr-x  1 kwilliams  admin  44 Jan 31  2023 /opt/homebrew/bin/emacs@ -> /Applications/Emacs.app/Contents/MacOS/Emacs

In general the keyboard shortcuts are great, having things like ⌘S and ⌘Q and ⌘A retain consistent behavior with typical Mac apps. One area that's different is copy/paste behavior, though:

  1. If I select a word (e.g. by double-clicking it) and do ⌘C to copy (which seems to invoke ns-copy-including-secondary), the act of copying it also deselects the word. A typical Mac application will leave it selected.
  2. If I then select another word (double-click) and do ⌘V (yank) to paste the copied word, Emacs seems to first deselect the selected word and then insert the copied text after it.

#1 isn't a super huge deal, but #2 makes it cumbersome to try to paste one copied string in multiple locations.

Is there a way to change the semantics of yank or bind ⌘V to something else that acts closer to the Mac's typical paste?

1 Answer 1

2

You'll want to enable delete-selection-mode. From C-h f delete-selection-mode RET:

When Delete Selection mode is enabled, typed text replaces the selection if the selection is active. Otherwise, typed text is just inserted at point regardless of any selection.

You can find more information about it at the Emacs wiki - DeleteSelectionMode, in the Emacs FAQ - 5.9 How can I replace highlighted text with what I type? , and Emacs Manual - 12.3 Operating on the Region

Additional further reading you may be interested in are 13.6 CUA Bindings and 22.1 Mouse Commands for Editing both from the Emacs Manual.

3
  • As an "emacs on macos" user, I generally stick with the defaults for such things, and enable delete-selection-mode as needed, which is rare.
    – nega
    Aug 5, 2023 at 17:10
  • Thanks! I notice the docs talk about "typed text". Is there a difference between typed text and yanked text in this context? I wonder why it doesn't just refer to it as "inserted text". Aug 14, 2023 at 16:47
  • 1
    No, there's no functional difference. I think the docs are just written from the perspective of keyboard interaction.
    – nega
    Aug 14, 2023 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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