How do I quickly convert between snake_case, camelCase, and other naming conventions in Vim?
Answer
crs
Explanation
The vim-abolish plugin by Tim Pope provides instant case coercion commands that convert the word under your cursor between common naming conventions. Instead of manually rewriting variable names when switching between languages or coding styles, a single cr command followed by a letter transforms the word in place.
How it works
Place your cursor on any word and press cr followed by the target case format:
crs " snake_case
crc " camelCase
crm " MixedCase (PascalCase)
cru " UPPER_CASE (SCREAMING_SNAKE)
cr- " dash-case (kebab-case)
cr. " dot.case
cr<space> " space case
crt " Title Case
Example
Starting with the variable myVariableName under the cursor:
crs → my_variable_name
crc → myVariableName
crm → MyVariableName
cru → MY_VARIABLE_NAME
cr- → my-variable-name
cr. → my.variable.name
Abolish intelligently detects word boundaries regardless of the current format. Converting from my_variable_name with crm correctly produces MyVariableName — it understands underscores, capital letters, hyphens, and dots as word separators.
Real-world use cases
- Porting code between Python and JavaScript: Python uses
snake_case, JavaScript usescamelCase. Place cursor on a variable, presscrcorcrsto convert instantly. - Writing CSS class names: Convert a JavaScript
camelCaseprop tokebab-casefor a CSS class withcr-. - Constants: Promote a regular variable to a constant with
cruto getSCREAMING_SNAKE_CASE. - Database columns to model attributes: Many ORMs map
snake_casedatabase columns tocamelCaseorPascalCasemodel properties.
Tips
- Case coercion is repeatable with
.if you have vim-repeat installed — apply the same conversion to multiple variables rapidly - Combine with search: use
*to find all occurrences of a variable, thencrs+n.n.n.to convert them one by one with review - Abolish also provides the
:Subvertcommand for case-aware search and replace across an entire file, which is even more powerful for bulk renaming