Advertisement
Guest User

Emacs kill and yank on the same hotkey.

a guest
Oct 21st, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.46 KB | None | 0 0
  1. (defun kill-ring-save-or-yank (&optional arg)
  2.   "Kills region if you marked anything, yanks if you didn't"
  3.   (interactive)
  4.   (cond ((use-region-p)
  5.      (call-interactively 'kill-ring-save))
  6.     ((eq last-command 'yank)
  7.      (call-interactively 'yank-pop))
  8.     (t
  9.      (call-interactively 'yank))))
  10. (global-set-key (kbd "M-w") 'kill-ring-save-or-yank) ;; change "M-w" to something else if you prefer it. "M-" means "Alt+", "C-" means "Ctrl+", "s-" means "Win+"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement