How do I convert between snake_case, camelCase, MixedCase, and UPPER_CASE using vim-abolish coercions?
Answer
crs / crm / crc / cru
Explanation
The vim-abolish plugin by Tim Pope adds a cr (coerce) prefix command that instantly converts the word under the cursor between common naming conventions. This is invaluable when renaming variables, translating code between styles, or refactoring identifiers across a codebase.
How it works
Place the cursor on any word and use one of these coercions:
crs— snake_case:myVariable→my_variablecrm— MixedCase (PascalCase):my_variable→MyVariablecrc— camelCase:my_variable→myVariablecru— UPPER_CASE:my_variable→MY_VARIABLEcr-— dash-case (kebab-case):my_variable→my-variablecr.— dot.case:my_variable→my.variablecrt— Title Case:my_variable→My Variable
Each coercion works on the word under the cursor in normal mode and respects word boundaries intelligently.
Example
With cursor on userProfileData:
const userProfileData = {};
Pressing crs converts it to:
const user_profile_data = {};
Then cru would convert it to:
const USER_PROFILE_DATA = {};
Tips
- Combine with
:sandgnfor project-wide renaming: search foruser_profile_data, thencrc.on each match to convert to camelCase - Works on acronyms too —
URLParserbecomesurl_parserwithcrs - vim-abolish also provides
:Subvertfor case-aware substitution across naming conventions in a single command - Install via any plugin manager:
tpope/vim-abolish