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


20.2 Words

Emacs has commands for moving over or operating on words. By convention, the keys for them are all Meta- characters.

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; drag a word forward or backward across other words (transpose-words).

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

The commands Meta-f (forward-word) and Meta-b (backward-word) move forward and backward over words. They are analogous to Control-f and Control-b, which move over single characters. Like their Control- analogues, Meta-f and Meta-b move several words if given an argument. Meta-f with a negative argument moves backward, and Meta-b with a negative argument moves forward. Forward motion stops after the last letter of the word, while backward motion stops before the first letter.

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

Meta-DEL (backward-kill-word) kills the word before point. It kills everything from point back to where Meta-b would move to. If point is after the space in ‘FOO, BAR, then ‘FOO,  is killed. To kill just ‘FOO’, type Meta-b Meta-d instead of Meta-DEL.

Meta-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, transposing ‘FOO, BAR results in ‘BAR, FOO rather than ‘BAR FOO,’. See Transpose, for more on transposition and on arguments to transposition commands.

To operate on the next n words with an operation which applies between point and mark, you can either set the mark at point and then move over the words, or you can use the command Meta-@ (mark-word) which does not move point but sets the mark where Meta-f would move to. It can be given arguments just like Meta-f.

The word commands’ understanding of syntax is completely controlled by the syntax table. For example, any character can be declared to be a word delimiter. See Syntax.


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