Superword- and Subword-Mode in Emacs 24.4

If you like—or are forced to use—camelCaseWords, Emacs has subword-mode that will cause word-based cursor movements to stop at each of the individual words. This can sometimes be useful when you repeatedly need to move to one of the constituent words of a series of compound words.

I rarely have a need to edit camel case words so I never need subword-mode but often have a related problem. In Emacs, when the cursor is in front (or behind) of compound-word or compound_word, moving by word will stop at each constituent word. That’s seldom what you want. You’d like to jump over the whole thing because you’re normally thinking of it as a single word.

As Xah Lee tells us, Emacs 24.4 will have superword-mode that will treat things like compound-word as a single word. That will be handy for programmers who often deal with compound-words or other_compound_words. Lee’s post has the details but notice how the two modes achieve a unification: with subword-mode you always move by word constituents; with superword-mode you always move by the entire compound word, no matter how it’s formed. That’s why the two modes are mutually exclusive.

This entry was posted in General and tagged . Bookmark the permalink.

2 Responses to Superword- and Subword-Mode in Emacs 24.4

  1. Phil says:

    Don’t forget glasses-mode which can be handy for people not used to reading camelCase.

    It’s also notable that since Emacs 24.3 subword-mode has been more customisable than it used to be. By default it’s still wired for camelCase of course, but these days you can modify subword-forward-regexp and subword-backward-regexp if you need to to tweak its behaviour, or assign custom functions to subword-forward-function and subword-backward-function for more complex changes.

    So if you have a use-case which should act rather like subword-mode but for different criteria; or simply want to make subword-mode “do what I want” for more situations, you can do that pretty easily.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>