GNU Emacs
Emacs
Dashboard

7.1 Inserting Text

You can insert an ordinary graphic character (e.g., ‘ a’, ‘ B’, ‘ 3’, and ‘ =’) by typing the associated key. This adds the character to the buffer at point. Insertion moves point forward, so that point remains just after the inserted text. See Point.

To end a line and start a new one, type RET ( newline). (The RET key may be labeled Return, or Enter, or with a funny-looking left-pointing arrow on your keyboard, but we refer to it as RET in this manual.) This command inserts a newline character into the buffer, then indents (see Indentation) according to the major mode. If point is at the end of the line, the effect is to create a new blank line after it and indent the new line; if point is in the middle of a line, the line is split at that position. To turn off the auto-indentation, you can either disable Electric Indent mode (see Convenience Features for Indentation) or type C-j, which inserts just a newline, without any auto-indentation.

As we explain later in this manual, you can change the way Emacs handles text insertion by turning on minor modes. For instance, the minor mode called Auto Fill mode splits lines automatically when they get too long (see Filling Text). The minor mode called Overwrite mode causes inserted characters to replace (overwrite) existing text, instead of shoving it to the right. See Minor Modes.

Only graphic characters can be inserted by typing the associated key; other keys act as editing commands and do not insert themselves. For instance, DEL runs the command delete-backward-char by default (some modes bind it to a different command); it does not insert a literal ‘ DEL’ character (ASCII character code 127).

To insert a non-graphic character, or a character that your keyboard does not support, first quote it by typing C-q ( quoted-insert). There are two ways to use C-q:

  • C-q followed by any non-graphic character (even C-g) inserts that character. For instance, C-q DEL inserts a literal ‘ DEL’ character.

  • C-q followed by a sequence of octal digits inserts the character with the specified octal character code. You can use any number of octal digits; any non-digit terminates the sequence. If the terminating character is RET, that RET serves only to terminate the sequence. Any other non-digit terminates the sequence and then acts as normal input—thus, C-q 1 0 1 B inserts ‘ AB’.

The use of octal sequences is disabled in ordinary non-binary Overwrite mode, to give you a convenient way to insert a digit instead of overwriting with it.

To use decimal or hexadecimal instead of octal, set the variable read-quoted-char-radix to 10 or 16. If the radix is 16, the letters a to f serve as part of a character code, just like digits. Case is ignored.

A few common Unicode characters can be inserted via a command starting with C-x 8. For example, C-x 8 [ inserts which is Unicode code-point U+2018 LEFT SINGLE QUOTATION MARK, sometimes called a left single “curved quote” or “curly quote”. Similarly, C-x 8 ], C-x 8 { and C-x 8 } insert the curved quotes , and , respectively. Also, a working Alt key acts like C-x 8 (unless followed by RET); e.g., A-[ acts like C-x 8 [ and inserts . To see which characters have C-x 8 shorthands, type C-x 8 C-h.

Alternatively, you can use the command C-x 8 RET ( insert-char). This prompts for the Unicode name or code-point of a character, using the minibuffer. If you enter a name, the command provides completion (see Completion). If you enter a code-point, it should be as a hexadecimal number (the convention for Unicode), or a number with a specified radix, e.g., #o23072 (octal); See Integer Basics in The Emacs Lisp Reference Manual. The command then inserts the corresponding character into the buffer.

For example, the following all insert the same character:

C-x 8 RET left single quotation mark RET
C-x 8 RET left sin TAB RET
C-x 8 RET 2018 RET
C-x 8 [
A-[  (if the Alt key works)
`    (in Electric Quote mode)

A numeric argument to C-q or C-x 8 ... specifies how many copies of the character to insert (see Numeric Arguments).

As an alternative to C-x 8, you can select the corresponding transient input method by typing C-u C-x \ iso-transl RET, then temporarily activating this transient input method by typing C-x \ [ will insert the same character (see transient input method).

In addition, in some contexts, if you type a quotation using grave accent and apostrophe `like this', it is converted to a form ‘like this’ using single quotation marks, even without C-x 8 commands. Similarly, typing a quotation ``like this'' using double grave accent and apostrophe converts it to a form “like this” using double quotation marks. See Quotation Marks.