Emacs: Move Cursor by camelCase, snake_case

By Xah Lee. Date: . Last updated: .

You can set emacs so that word moving commands will move cursor into between CamelCaseWords, or treat snake_case as one single word.

Alt+x subword-mode
Change all cursor movement/edit commands to stop in-between the “camelCase” words.
Alt+x superword-mode
Change all cursor movement/edit commands to treat text like “x_y” as one word. Useful for “snake_case”.
Alt+x global-subword-mode
Toggle on/off globally.
Alt+x global-superword-mode
Toggle on/off globally.
emacs normal/subword/superword modes.
Cursor position from left to right
normalsubwordsuperword
someThing▮
some▮-thing
some▮_thing
some▮Thing
some▮-thing
some▮_thing
someThing▮
some-thing▮
some_thing▮

subword-mode and superword-mode are mutally exclusive. Turning one on turns off the other.

Put this in your Emacs Init File:

;; move cursor by camelCase
(global-subword-mode 1)
;; 1 for on, 0 for off