Next: Expanding Abbrevs, Previous: Abbrev Concepts, Up: Abbrevs [Contents][Index]

### 29.2 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 define-global-abbrev RET abbrev RET exp RET`

  Define abbrev as an abbrev expanding into exp.

`M-x define-mode-abbrev RET abbrev RET exp RET`

  Define abbrev as a mode-specific abbrev expanding into exp.

`M-x kill-all-abbrevs`

  Discard all abbrev definitions, 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 for the current major mode. The arguments work the same as for `C-x a g`.

`C-x a i g` (`inverse-add-global-abbrev`) and `C-x a i l` (`inverse-add-mode-abbrev`) perform the opposite task: if the abbrev text is already in the buffer, you use these commands to define an abbrev by specifying the expansion in the minibuffer. These commands will expand the abbrev text used for the definition.

You can define an abbrev without inserting either the abbrev or its expansion in the buffer using the command `define-global-abbrev`. It reads two arguments—the abbrev, and its expansion. The command `define-mode-abbrev` does likewise for a mode-specific abbrev.

To change the definition of an abbrev, just make a new definition. When an abbrev has a prior definition, the abbrev definition commands ask for confirmation before 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 abbrev definitions, both global and local.

Next: Expanding Abbrevs, Previous: Abbrev Concepts, Up: Abbrevs [Contents][Index]