Emacs: Copy, Paste, Append, Clear, Register 1 📜

By Xah Lee. Date: . Last updated: .

Here's a command that lets you copy paste text to register 1.

put them in your Emacs Init File:

Copy to Register 1

(defun xah-copy-to-register-1 ()
  "Copy selection or text block to register 1.
URL `http://xahlee.info/emacs/emacs/elisp_copy-paste_register_1.html'
Created: 2012-07-17
Version: 2025-11-05"
  (interactive)
  (let (xbeg xend)
    (seq-setq (xbeg xend) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point))))))
    (copy-to-register ?1 xbeg xend)
    (message "Copied to register 1: %s." (buffer-substring xbeg xend))))

Paste from Register 1

(defun xah-paste-from-register-1 ()
  "Paste text from register 1.
URL `http://xahlee.info/emacs/emacs/elisp_copy-paste_register_1.html'
Created: 2015-12-08
Version: 2025-11-07"
  (interactive)
  (when (region-active-p)
    (delete-region (region-beginning) (region-end)))
  (insert-register ?1 t))

Append to Register 1

This command lets you append text to register 1.

(defun xah-append-to-register-1 ()
  "Append selection or text block to register 1,
with one added newline char at end.
URL `http://xahlee.info/emacs/emacs/elisp_copy-paste_register_1.html'
Created: 2015-12-08
Version: 2025-11-07"
  (interactive)
  (let (xbeg xend)
    (seq-setq (xbeg xend) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point))))))
    (let ((register-separator "\n"))
      (append-to-register ?1 xbeg xend)
      (message "Done. Append to register 1."))))

Clear Register 1

With append to register 1, sometimes you need to clear it first.

Here's command to clear register 1.

(defun xah-clear-register-1 ()
  "Clear register 1.
URL `http://xahlee.info/emacs/emacs/elisp_copy-paste_register_1.html'
Created: 2015-12-08
Version: 2025-11-07"
  (interactive)
  (progn
    (copy-to-register ?1 (point-min) (point-min))
    (message "Cleared register 1.")))

Set Keys

these commands need to have easy keys to be useful. e.g.

Why these commands?

When you call {copy-to-register, insert-register}, each time you have to tell it which register to use. Rather annoying. 〔see Emacs: Copy to Register

Most of the time all you need is one register.

The single key commands xah-copy-to-register-1 and xah-paste-from-register-1 by-pass the asking and just use register 1.

This saves you 2 key strokes and a brain cycle.

Emacs, copy paste