Emacs defines several commands for moving over or operating on words:
Move forward over a word (
Move backward over a word (
Kill up to the end of a word (
Kill back to the beginning of a word (
Set mark at the end of the next word (
Transpose two words or drag a word across others
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.
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.
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
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 Transposing Text, 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 Commands to Mark Textual 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 Cursor Position Information 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.