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

How do I quickly convert between snake_case, camelCase, and other naming conventions in Vim?

Answer

crs / crm / crc / cru

Explanation

Tim Pope's vim-abolish plugin provides cr (coerce) commands that instantly convert the word under the cursor between common naming conventions. This is a massive time-saver when working across languages with different naming styles — for example, converting a Python snake_case variable to JavaScript camelCase, or a Go MixedCase type to a SQL UPPER_CASE constant.

How it works

  • crs — Coerce to snake_case (my_variable_name)
  • crm — Coerce to MixedCase / PascalCase (MyVariableName)
  • crc — Coerce to camelCase (myVariableName)
  • cru — Coerce to UPPER_CASE (MY_VARIABLE_NAME)
  • cr- — Coerce to dash-case / kebab-case (my-variable-name)
  • cr. — Coerce to dot.case (my.variable.name)

The plugin intelligently detects the current casing format, so it works regardless of the starting convention.

Example

With cursor on myVariableName:

crs → my_variable_name
crm → MyVariableName
cru → MY_VARIABLE_NAME
cr- → my-variable-name

Tips

  • Install with your package manager: Plug 'tpope/vim-abolish'.
  • The plugin also provides :Subvert, a case-aware version of :substitute that handles all case variants at once: :Subvert/old/new/g replaces old, Old, OLD, etc.
  • Works on the word under the cursor — no visual selection needed.
  • Combine with . to repeat the same coercion on other words.

Next

How do I return to normal mode from absolutely any mode in Vim?