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

How do I uppercase a word in Vim?

Answer

gUiw

Explanation

The gUiw command converts the entire word under the cursor to uppercase. It combines the gU operator (make uppercase) with the iw (inner word) text object.

How it works

  • gU triggers the uppercase operator
  • iw selects the inner word under the cursor

Example

Given the text with the cursor on hello:

say hello to vim

Pressing gUiw results in:

say HELLO to vim

The word hello is converted to HELLO. The cursor can be anywhere on the word.

Tips

  • Use guiw to convert a word to lowercase instead
  • Use g~iw to toggle the case of each character in the word
  • Use gUU or gU_ to uppercase the entire current line
  • Use gUap to uppercase an entire paragraph
  • In visual mode, select text and press U to uppercase or u to lowercase
  • Use ~ to toggle the case of the single character under the cursor and advance

Next

How do I edit multiple lines at once using multiple cursors in Vim?