Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In emacs there are the functions forward-word and backward-word. Are there also functions which move the point to the next/last whitespace?

share|improve this question
Isn't this for a lot of cases equivalent? What is the use case there a different functionality is needed? – H.-Dirk Schmitt Oct 31 '12 at 15:57
For example if a have a generalized word like \a_command_with_special-characters – Julia Oct 31 '12 at 16:21
up vote 6 down vote accepted

You can modify the syntactical properties of characters using the modify-syntax-entry function (C-h f modify-syntax-entry in emacs for more info):

For instance, if you are writing .tex documents, you might add the following to your .emacs:

 '(lambda ()
    (modify-syntax-entry ?_ "w")
    (modify-syntax-entry ?- "w")

This tells emacs to treat _ and - as "word" characters when you are in TeX mode, thus forward-word and backward-word will do what you want.

share|improve this answer

Use forward-whitespace to advance by spaces, tabs or newlines. Multiple spaces are treated as one delimiter. With a negative argument, go backwards by that number of whitespaces.

share|improve this answer
Any idea how to advance to the first whitespace after a block of text, without skipping any? forward-whitespace seems to skip to the end of the line when I have trailing spaces on a line. I really just want to find the first trailing space. Thanks for any help. – Dave Nov 13 '15 at 8:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.