Studly Next

Summary: Jump to the next intra-word. Works like a finer-grained Option-Rightarrow.
Requires: BBEdit 8 (similar functionality built-into BBEdit 8.5)
Suggested Key Binding: Control-Rightarrow
Last Modified: 2019-10-02


This script brings CodeWarrior’s Control-Rightarrow functionality to BBEdit. It lets you jump between the parts of words with with inner caps (a.k.a. studly caps or camel case). This is very useful for programmers who follow the Apple or Java naming conventions.

This script works like a finer-grained Option-Rightarrow. Instead of moving to the next word, it moves to the next capitalized part of a word. For instance, the underscored positions in: _set_Script_Error_Number_.

Installation Instructions · Download in Compiled Format · Download in Text Format


property wordCharacters : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"

-- FIXME: doesn't advance past word at end of document

on run
tell application "BBEdit"
tell window 1
set oldOffset to characterOffset of selection
set firstChar to character oldOffset as string
set inWordNow to my isWordCharacter(firstChar)
repeat with newOffset from oldOffset + 1 to count characters
set c to character newOffset as string
if my stopHere(c, inWordNow) then
select insertion point after character (newOffset - 1)
end if
end repeat
end tell
end try
end tell
end run

on stopHere(c, inWordNow)
if isCapitalLetter(c) then
return true
else if not isWordCharacter(c) then
return true
else if not inWordNow and isWordCharacter(c) then
return true
return false
end if
end stopHere

on isCapitalLetter(c)
if (ASCII number of c) is greater than or equal to 65 ¬
and (ASCII number of c) is less than 97 then
return true
return false
end if
end isCapitalLetter

on isWordCharacter(c)
return wordCharacters contains c
end isWordCharacter