How do I convert a word between snake_case, camelCase, MixedCase, and kebab-case with a single keystroke?
Answer
cr{s/m/c/k/u}
Explanation
The vim-abolish plugin provides cr{type} coercions that instantly convert the word under the cursor to a different naming convention. This eliminates tedious manual renaming when porting code between languages or enforcing a consistent style.
How it works
With the cursor on any word, press cr followed by one of these type keys:
| Keypress | Converts to | Example |
|---|---|---|
crs |
snake_case | my_variable |
crm |
MixedCase | MyVariable |
crc |
camelCase | myVariable |
crk |
kebab-case | my-variable |
cru |
UPPER_SNAKE_CASE | MY_VARIABLE |
crt |
Title Case | My Variable |
cr. |
dot.case | my.variable |
The coercion is smart about word boundaries — it correctly handles transitions like myHTTPClient → my_http_client and back.
Example
With the cursor on userProfileData:
Before: userProfileData
Press crs:
After: user_profile_data
Press crm on user_profile_data:
After: UserProfileData
Tips
- Works from any position within the word, not just at the start
- Combine with
.to repeat the same coercion on the next occurrence (n.after the first conversion) - Use vim-abolish's
Subvertcommand for multi-form substitution across a file::%Subvert/blog_post{,s}/article{,s}/g - Install with your plugin manager:
Plug 'tpope/vim-abolish'