brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gU and gu in Vim change text to upper or lower case

Vim
~/tips/tip-vim-change-case

gUiw

Changes the case of a word, a line or a selection.

Turning a constant into uppercase or fixing a heading that was typed with caps lock on: Vim has case operators that work with any motion.

gUiw
guiw
g~iw

gU makes text uppercase, gu lowercase, and g~ swaps the case of every letter. They are operators, so they take a motion or text object, just like d or c. iw is the word under the cursor.

Doubling the last letter works on the whole line:

gUU
guu
g~~

And any motion works: gU$ to the end of the line, gUap for a paragraph. In visual mode the keys are shorter: U and u for the selection, and ~ to swap.

For a single character there is plain ~ in normal mode. It swaps the case and moves one to the right, so pressing it a few times walks along a word.

The one I’d be careful with is u. In visual mode it lowercases the selection, in normal mode it is undo. If you meant to lowercase and nothing was selected any more, you just undid your last change, and Ctrl-r brings it back.

Further reading: Vim help: gU, Vim help: switching case

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link