Struggling to quickly switch entire words from upper to lower case or just toggle a single character in Vim? Vim’s whims can make changing letter case seem tricky. Find out here how to change case in Vim and Neovim ⤓ (to upper, lower and title case) with confident agility.
On This Page
How to Change Case in Vim (to Upper, Lower or Title)
In Normal Mode
Time needed: 1 minute
To change the case of text in Vim or Neovim using normal mode:
- Position the cursor on the character, word, line or paragraph you want to change.
- Enter normal mode.
Here’s how: Typically, press Esc to enter normal mode in Vim.
- Press G.
Just one letter: Press ~ (tilde) instead to toggle the case for the current character immediately (from upper to lower or vice versa) and move one character to the right.
- Now press the key or key combination for the desired case change.
Here’s which: In general, use U for lower case, Shift U for upper case and ~ to toggle the current case; see the table below.
- Specify the range to which the change should apply.
Here’s how: All “motion” command in Vim work, e.g.,
Wchanges until the end of the current word,Afollowed byPchange the current paragraph and a repletion of the command changes the current line.
Examples:gUaw: changes the current word to upper caseguu: makes the current line all lowercaseg~i): toggles case for everything in the closest pair of parentheses
Their word: Vim includes information on changing case in its documentation.
Vim cAse coMManDs MaSteREd?
Tips help fuel these email and tech how-tos.
Using Visual Mode
Of course, you can also use visual mode to first make the selection and then apply a case change:
- Press V for visual mode, Shift V for visual line mode or Ctrl V for visual block mode.
- Use the motion keys to select the portion of text you want to edit.
- Press the key or key combination for the desired case change.
Here’s which: see the table below for an overview.
Changing more? How to Search and Replace in Vim
A change gone wrong? How to Undo in Vim
Vim Keys for Case Toggling (to Upper, to Lower, and Switch)
| Vim Key | Action |
|---|---|
| U | to lower case |
| Shift U | to upper case |
| ~ | toggle case |
| Z | title case (using the Vim Titlecase plugin) |
How to Change Case in Vim (to Upper, Lower, etc.): FAQ
Can I toggle the case in Vim insert mode?
Yes.
While Vim does not come with ready-made commands to change case in insert mode, you can add your own mappings easily.
Example: To set up a Ctrl L to toggle case for the previously typed word, add the following to your .vimrc file:
inoremap <C-L> <Esc>g~iw`]aThen, for instance, type exit_success and press Ctrl L immediately (and without adding whitespace) to change the whole word to upper case EXIT_SUCCESS.
Can I switch to title case in Vim?
Using search and replace, you can get a basic version of title case in Vim. To change the first letter of each word to upper case with Vim:
- Highlight the portion of text you want to change to title case using visual mode or visual line mode.
- Press : for the Vim command line.
- Now type
s/\(w+)/\u\1\L\2/gto replace the first letter with its uppercase equivalent in each word.
Example: With a selection, the command line will read :'<,'>s/\(w+)/\u\1\L\2/g.
Headlines: Note that this does not respect headline capitalization conventions.
Alternative: The Vim Titlecase plugin adds a title case operator to Vim that you can use like the other case keys. - Press Enter.
(Tested with Vim 9.0–9.1 and Neovim 0.10–0.12; first published September 2023, last updated June 2026)