It is also a lot to read. This document aims to be an introduction and quick reference.
Emacs terms were established a long time ago and are not typical.
Table: Emacs Lexicon
|Standard term||Emacs term||to cut||to kill|
|to copy||to save to the kill ring|
|to paste||to yank|
|the clipboard||the kill ring|
|Alt||Meta, usually (e.g., M-w is usually Alt-w)|
|selected text||the region, bounded by the cursor (point) and mark|
|NA||mark: start or end of selected text|
Copying in Emacs
Copying in Emacs does not have as many commands as cutting. For example, there are two commands for cutting lines (kill-line & kill-whole-line), but not for copying lines. Copying can be achieved by doing a cut (kill) followed either by an undo (C-x u) or by a yank (paste) (C-y), or by selecting text (either with mouse or keyboard) then doing kill-ring-save (M-w).
Emacs Clipboard a.k.a. Kill Ring
The kill ring (clipboard) of Emacs contains more than the most recently copied/cut text; the kill ring contains a list (by default 60 at most) of recent copied/cut text. This is a very useful feature. It is a list with wraparound behavior—when you access past its end, it goes back to the beginning, and vice versa. Hence, it behaves like a circular list or “ring”.
Viewing the Clipboard (Kill Ring) and Selecting an Entry to Paste
Pasting, by default, accesses the most recently cut/copied text. With Emacs, you have a history of text entries to choose from. In a GUI version of Emacs, click the Edit menu (or hit F10 if it’s not visible), then move the mouse over “Paste from Kill Menu”, and you will see many of the recent entries. You can click on one to paste it. In a text-only version of Emacs, you achieve the same thing by navigating with keys instead of a mouse. Again, start with menu-bar-open F10.
Table: Useful commands for copying and pasting in Emacs
|kill-region||C-w||cut selected text||like Control-x|
|kill-ring-save||M-w||copy selected text||like Control-c|
|menu-bar-open||F10||Edit menu is useful|
|kill-line||C-k||cut line to end|
|kill-whole-line||C-S-backspace||cut entire line||key works only in GUI|
|set-mark-command||C-SPC or C-@||start selecting text|
|undo||C-/ or C-_ or C-x u||use after kill to restore text|
Selecting Text With the Keyboard
In Emacs, you can use the keyboard to select the text, then copy or cut it. First, put the cursor (or “point”) at the start of the text you want to select, then press C-SPC. Then, navigate the cursor to the end of the text you want to select. You should see the selected text highlighted. Now, use C-w or M-w to cut or copy.
This article highlighted the process of copying and pasting using Emacs through the use of the Emacs terminology. In addition, useful commands and the efficient use of the keyboard to utilize the copy and paste commands were discussed. We hope you found these tips helpful and encourage you to check out our other articles at Linux Hint.