Emacs: Copy Buffer or Selection 📜
This page shows you emacs commands to copy/cut whole buffer, or text text selection if there's one.
Copy All or Text Selection
put this in your Emacs Init File:
(defun xah-copy-all-or-region () "Copy buffer or selection content to `kill-ring'. Respects `narrow-to-region'. URL `http://xahlee.info/emacs/emacs/emacs_copy_cut_all_or_region.html' Created: 2015-08-22 Version: 2015-08-22" (interactive) (if (region-active-p) (progn (kill-new (buffer-substring (region-beginning) (region-end))) (message "Text selection copied.")) (progn (kill-new (buffer-string)) (message "Buffer content copied."))))
This command saves you a step of doing selecting whole buffer first.
You should define a key for it. 〔see Emacs Keys: Define Key〕
Cut All or Text Selection
put this in your Emacs Init File:
(defun xah-cut-all-or-region () "Cut buffer or selection content to `kill-ring'. Respects `narrow-to-region'. URL `http://xahlee.info/emacs/emacs/emacs_copy_cut_all_or_region.html' Created: 2015-08-22 Version: 2025-08-06" (interactive) (if (region-active-p) (progn (kill-new (buffer-substring (region-beginning) (region-end))) (delete-region (region-beginning) (region-end))) (progn (kill-new (buffer-string)) (delete-region (point-min) (point-max)) (message "buffer text cut"))))
Emacs, copy paste
- Emacs: Select Text (mark and region)
- Emacs: Copy Paste, kill-ring
- Emacs: Copy Current Line 📜
- Emacs: Copy Buffer or Selection 📜
- Emacs: Paste or Paste Previous 📜
- Emacs: Show Copy History (kill-ring) 📜
- Emacs Init: Standard Copy Cut Paste Keys
- Emacs: Copy to Register
- Emacs: Copy, Paste, Append, Clear, Register 1 📜