Next: Sentences, Up: Text [Contents][Index]

### 25.1 Words

Emacs defines several commands for moving over or operating on words:

`M-f`

  Move forward over a word (`forward-word`).

`M-b`

  Move backward over a word (`backward-word`).

`M-d`

  Kill up to the end of a word (`kill-word`).

`M-DEL`

  Kill back to the beginning of a word (`backward-kill-word`).

`M-@`

  Mark the end of the next word (`mark-word`).

`M-t`

  Transpose two words or drag a word across others (`transpose-words`).

Notice how these keys form a series that parallels the character-based `C-f`, `C-b`, `C-d`, `DEL` and `C-t`. `M-@` is cognate to `C-@`, which is an alias for `C-SPC`.

The commands `M-f` (`forward-word`) and `M-b` (`backward-word`) move forward and backward over words. These `META`-based key sequences are analogous to the key sequences `C-f` and `C-b`, which move over single characters. The analogy extends to numeric arguments, which serve as repeat counts. `M-f` with a negative argument moves backward, and `M-b` with a negative argument moves forward. Forward motion stops right after the last letter of the word, while backward motion stops right before the first letter.

`M-d` (`kill-word`) kills the word after point. To be precise, it kills everything from point to the place `M-f` would move to. Thus, if point is in the middle of a word, `M-d` kills just the part after point. If some punctuation comes between point and the next word, it is killed along with the word. (If you wish to kill only the next word but not the punctuation before it, simply do `M-f` to get the end, and kill the word backwards with `M-DEL`.) `M-d` takes arguments just like `M-f`.

`M-DEL` (`backward-kill-word`) kills the word before point. It kills everything from point back to where `M-b` would move to. For instance, if point is after the space in ‘`FOO, BAR`’, it kills ‘`FOO,` ’. If you wish to kill just ‘`FOO`’, and not the comma and the space, use `M-b M-d` instead of `M-DEL`.

`M-t` (`transpose-words`) exchanges the word before or containing point with the following word. The delimiter characters between the words do not move. For example, ‘`FOO, BAR`’ transposes into ‘`BAR, FOO`’ rather than ‘`BAR FOO,`’. See Transpose, for more on transposition.

To operate on words with an operation which acts on the region, use the command `M-@` (`mark-word`). This command sets the mark where `M-f` would move to. See Marking Objects, for more information about this command.

The word commands’ understanding of word boundaries is controlled by the syntax table. Any character can, for example, be declared to be a word delimiter. See Syntax Tables in The Emacs Lisp Reference Manual.

In addition, see Position Info for the `M-=` (`count-words-region`) and `M-x count-words` commands, which count and report the number of words in the region or buffer.

Next: Sentences, Up: Text [Contents][Index]