Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set initial caps in VIM?

In VIM, it's really easy to change a word of text to use uppercase or lowercase:

# in visual mode

# change word to uppercase
gUw

# change word to lowercase
guw

Is there a simple way to modify the word to use initial caps?

like image 416
MCS Avatar asked Jul 06 '10 16:07

MCS


People also ask

How do you capitalize the first letter in Vim?

You can change the case of text: Toggle case " HellO " to " hELLo " with g~ then a movement. Uppercase " HellO " to " HELLO " with gU then a movement. Lowercase " HellO " to " hello " with gu then a movement.

What Vim command can you use to flip the case of a single letter lower case to upper case and vice versa )?

Switch case You can switch the case of the alpha character underneath your cursor in vi the tilde key ( ~ ). Doing so shifts from lowercase to uppercase and vice versa.

How do you use a change case?

Change case Select the text for which you want to change the case. Go to Home > Change case . Do one of the following: To capitalize the first letter of a sentence and leave all other letters as lowercase, click Sentence case.

How do I select a word in Vim?

You can use * and/or # to search for the word under the cursor or viw to visually select the word under the cursor.


2 Answers

Assuming cursor is at the beginning of the word, use

gUl

(if the word was all-lowercase) or

gUllgue

to explicitly make the first letter capital and other lower case.

It's the same that you used, only instead of w (word motion) you use l (one symbol motion).

If the cursor is somewhere in the middle of the word, prepend b (go to the beginning of the word) to the commands above.

You can map some key to do this if you use it often.

like image 99
Roman Cheplyaka Avatar answered Nov 15 '22 09:11

Roman Cheplyaka


I'd suggest moving to the beginning of the word with whatever motion command(s) you want, then pressing ~. This behavior is affected by the tildeop option, see :help ~ and :help tildeop for more info.

like image 27
Randy Morris Avatar answered Nov 15 '22 10:11

Randy Morris