How do I convert variable names between snake_case, camelCase, and other naming conventions with vim-abolish?
Answer
crs / crc / crm / cru
Explanation
The vim-abolish plugin adds coercion operators that instantly convert the word under the cursor between common naming conventions. Place your cursor on any identifier and type cr followed by a letter to transform it — no visual selection or manual editing required.
How it works
crs— convert tosnake_casecrc— convert tocamelCasecrm— convert toMixedCase(PascalCase)cru— convert toUPPER_SNAKE_CASEcrk— convert tokebab-casecrt— convert toTitle Casecrd— convert todot.case
The conversion is smart: it understands word boundaries in all forms, so fooBar, foo_bar, FOO_BAR, and FooBar all correctly round-trip to any target format.
Example
With the cursor on getUserName:
getUserName
Press crs to get:
get_user_name
Press crm to get:
GetUserName
Press cru to get:
GET_USER_NAME
Tips
- Combine with
.to repeat the same coercion on the next identifier after usingnto jump to it - Use
:Subvert/identifier/replacement/gfrom the same plugin for multi-form substitutions across a file (it matches all case variants at once) - Install via any plugin manager:
tpope/vim-abolish