Friday, February 11, 2011

Vim Usage: Change upper case/lower case

I am addicted to use vim all the time, in programming (except eclipse), in text editing. I like to use it since it increase my working progress and the command helps me a lot.

I am going to post some notes when I learn some new useful command/macro.
One useful function is to change letter case. For one character, you can simply use "~" to change to case from upper to lower or vice versa.

However, what if I want to change whole passage to UPPERCASE or lowercase. We can use gU / gu command.

1. Change whole passage to lower case
you can use "ggguG" in command mode.

Explain:
  • gg - go to the first line and first character
  • gu - change letter to lower case
  • G - go to the last character of last line
Thus, it goes to the first character, change to lower case until the last character.

2. You can use motion command to change case

guw、gue、gUw、gUe

3. some special combinations

  • gUU - change current line to uppercase
  • 10gUU - change 10 lines including current line to uppercase
  • gU0 - change first character of current line to uppercase
  • gU$ - change last character of current line to uppercase
  • gUG - change character from current position to last charactor of last line

No comments:

Post a Comment