GNU Emacs Manual - Defining Abbrevs

Go to the first, previous, next, last section, table of contents.

## Defining Abbrevs

`C-x a g`
  Define an abbrev, using one or more words before point as its expansion (`add-global-abbrev`).
`C-x a l`
  Similar, but define an abbrev specific to the current major mode (`add-mode-abbrev`).
`C-x a i g`
  Define a word in the buffer as an abbrev (`inverse-add-global-abbrev`).
`C-x a i l`
  Define a word in the buffer as a mode-specific abbrev (`inverse-add-mode-abbrev`).
`M-x kill-all-abbrevs`
  This command discards all abbrev definitions currently in effect, leaving a blank slate.

The usual way to define an abbrev is to enter the text you want the abbrev to expand to, position point after it, and type `C-x a g` (`add-global-abbrev`). This reads the abbrev itself using the minibuffer, and then defines it as an abbrev for one or more words before point. Use a numeric argument to say how many words before point should be taken as the expansion. For example, to define the abbrev ``foo'` as mentioned above, insert the text ``find outer otter'` and then type `C-u 3 C-x a g f o o `RET``.

An argument of zero to `C-x a g` means to use the contents of the region as the expansion of the abbrev being defined.

The command `C-x a l` (`add-mode-abbrev`) is similar, but defines a mode-specific abbrev. Mode-specific abbrevs are active only in a particular major mode. `C-x a l` defines an abbrev for the major mode in effect at the time `C-x a l` is typed. The arguments work the same as for `C-x a g`.

If the text already in the buffer is the abbrev, rather than its expansion, use command `C-x a i g` (`inverse-add-global-abbrev`) instead of `C-x a g`, or use `C-x a i l` (`inverse-add-mode-abbrev`) instead of `C-x a l`. These commands are called "inverse" because they invert the meaning of the two text strings they use (one from the buffer and one read with the minibuffer).

To change the definition of an abbrev, just define a new definition. When the abbrev has a prior definition, the abbrev definition commands ask for confirmation for replacing it.

To remove an abbrev definition, give a negative argument to the abbrev definition command: `C-u - C-x a g` or `C-u - C-x a l`. The former removes a global definition, while the latter removes a mode-specific definition.

`M-x kill-all-abbrevs` removes all the abbrev definitions there are, both global and local.

Go to the first, previous, next, last section, table of contents.