Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Change case of selected characters in vi UNIX
I do a lot of editing with vi and came across a neat trick tonight. If you want to convert letters to upper or lower case without having to retype them, simply hold Fn + Shift + Page Up or Page Down. Whatever character is under the cursor will change case. This is useful to me since I sometimes have to change variable names to all upper or lower case. Holding the key combo down will do the complete line.

[robg adds: My desktop Mac lacks the Fn key, so I tried this hint with Shift + Page Up/Down alone, and it worked as described. Then I tested on my PowerBook, which does have the Fn key. Very strangely, I couldn't get this hint to work at all at first. A bit of digging revealed the answer: the PowerBook's terminal type was set to xterm-color (in Preferences, "Declare terminal type ($TERM) as"). Once I set it back to VT100, it worked as described. I think this trick is relying on VT100 terminal codes (someone will correct me if I'm wrong, I'm sure), so it failed when set to xterm-color. Also, it doesn't matter whether you use Page Up or Page Down -- either key merely toggles the case of the currently highlighted character.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[10,501 views]  

Change case of selected characters in vi | 7 comments | Create New Account
Click here to return to the 'Change case of selected characters in vi' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change case of selected characters in vi
Authored by: muttley8 on Jun 01, '04 11:08:37AM

You can also use the '~' charachter ( shift-`) to change case. One less key to hold down :-)



[ Reply to This | # ]
Change case of selected characters in vi
Authored by: sayler on Jun 01, '04 12:03:32PM

For reference (I'm sure you know this) ~ is a bog-standard vi key for case-toggle.

Maybe there should be a "stuipid vi tricks" hint? :-)



[ Reply to This | # ]
vim extension
Authored by: zojas on Jun 01, '04 12:22:35PM

in vim, you can press the g key, then the ~ key, then ANY cursor movement (e.g., w, e, $, G, }, 2j, 'b, whatever) and all the text which the cursor would have moved over will have its case toggled. cool, huh?



[ Reply to This | # ]
vim extension
Authored by: thaigan on Jun 10, '04 01:39:41AM

A couple more useful ones:
3~ reverses case for three characters
g~~ reverses case for the whole line



[ Reply to This | # ]
vim extension
Authored by: thaigan on Jun 10, '04 01:42:28AM

I meant to mention these useful ones too:
guu lowercase line
gUU uppercase line



[ Reply to This | # ]
Change case of selected characters in vi
Authored by: BobHarris on Jun 01, '04 05:55:55PM

Shift/Page up is <Escape>[5~ and Shift/Page down is <escape>[6~

The important thing is that it contains a tilda ~ and a ~ is the vi change case character.

And since vi on Mac OS X 10.3 is actually Vim, you can use the v, V, or Control/V characters to start a select range, move the cursor to a the end of the select range, then press ~ and change all the charcters in the select range.

Vim is powerful stuff.

Bob Harris



[ Reply to This | # ]
Vim tips
Authored by: blueaudio on Jun 01, '04 06:04:39PM

Vim has a lot of power, and I'm constantly learning new shortcuts and techniques. I've always picked up new ideas bit by bit, but if you have the time, you could learn a lot of this stuff once and use it for life.

http://www.vim.org/tips/tip.php?tip_id=305



[ Reply to This | # ]