How do I convert the entire current line to lowercase or uppercase in one command?
Answer
guu / gUU
Explanation
Vim's case operators gu (lowercase) and gU (uppercase) follow the same doubling convention as dd and yy: repeating the operator letter applies it to the whole current line. guu lowercases the line; gUU uppercases it — no motion or text-object needed.
How it works
guu— convert the current line to all lowercasegUU— convert the current line to all UPPERCASEg~~— toggle the case of every character on the current line- These are shorthand forms;
gul/gUl+$would achieve the same result but are more verbose - A count prefix affects multiple lines:
3guulowercases 3 lines starting from the current
Example
Before:
Const API_BASE_URL = 'https://Api.Example.Com';
After guu:
const api_base_url = 'https://api.example.com';
After gUU (from the original):
CONST API_BASE_URL = 'HTTPS://API.EXAMPLE.COM';
Tips
- For finer granularity:
guiwlowercases the current word,gUiwuppercases it guuis especially handy when normalizing ALL-CAPS constants or accidentally-shifted lines- In Visual mode, select a range of lines and press
u(lowercase) orU(uppercase) to apply case conversion to the entire selection - The case operators respect multibyte characters in most cases, though behavior depends on the locale and Vim's
encodingsetting