vimtricks.wiki Concise Vim tricks, one at a time.

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 to snake_case
  • crc — convert to camelCase
  • crm — convert to MixedCase (PascalCase)
  • cru — convert to UPPER_SNAKE_CASE
  • crk — convert to kebab-case
  • crt — convert to Title Case
  • crd — convert to dot.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 using n to jump to it
  • Use :Subvert/identifier/replacement/g from 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

Next

How do I mark and delete multiple files at once from within Vim's built-in file explorer netrw?