Hopping a word at a time is what makes navigation fast. Today you add word-wise motion that skips to the start of the next word and back to the start of the previous one.
Move the cursor to the next word's start and the previous word's start along a line.
Word motion turns navigation from a crawl into a hop. The rule is defined by what
counts as a word character - here a letter or digit - with everything else
(spaces, punctuation) acting as a separator. MoveWordRight skips the rest of the
word you are in, then skips the separators after it, and lands on the first
character of the next word. MoveWordLeft does the reverse: skip separators to the
left, then skip the word behind them, stopping at that word’s start.
The edges are where this earns its test. Moving right off the last word has no next
word to find, so it clamps at the line end rather than running past it; moving
left from the first word stops at column 0. Keeping the motion within a single
line for now keeps the rule crisp - one line, one scan, clear word boundaries - and
matches how MoveLeft and MoveRight stayed on their line too. The behavior is
the familiar Ctrl-arrow jump, built from one clear definition of where a word
begins.
// a "word char" is a letter or digit; anything else separates words.// MoveWordRight: skip the current run of word chars, then skip the// separators, landing on the next word's first char (or the line end).// MoveWordLeft is the mirror: skip separators left, then skip word chars.func isWord(c byte) bool { /* letter or digit */ }