Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert all text to lowercase in Vim

People also ask

How do you change all caps to lowercase in vim?

Visual select the text, then U for uppercase or u for lowercase. To swap all casing in a visual selection, press ~ (tilde). Without using a visual selection, gU<motion> will make the characters in motion uppercase, or use gu<motion> for lowercase. For more of these, see Section 3 in Vim's change.

What vim command can you use to flip the case of a single letter?

Key: g flag (I couldn't find a good reference for this...) ~ toggle case; alternatively use U for to-upper or u for to-lower.

What vim command can you use to flip the case of a single letter lower case to upper case 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 I delete a character in vim?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap.


I assume you want lowercase the text. Solution is pretty simple:

ggVGu

Explanation:

  1. gg - goes to first line of text
  2. V - turns on Visual selection, in line mode
  3. G - goes to end of file (at the moment you have whole text selected)
  4. u - lowercase selected area

  1. If you really mean small caps, then no, that is not possible – just as it isn’t possible to convert text to bold or italic in any text editor (as opposed to word processor). If you want to convert text to lowercase, create a visual block and press u (or U to convert to uppercase). Tilde (~) in command mode reverses case of the character under the cursor.

  2. If you want to see all text in Vim in small caps, you might want to look at the guifont option, or type :set guifont=* if your Vim flavour supports GUI font chooser.


use this command mode option

ggguG


gg - Goto the first line 
g  - start to converting from current line    
u  - Convert into lower case for all characters
G  - To end of the file.

Similar to mangledorf's solution, but shorter and layman friendly

:%s/.*/\L&/g


Many ways to skin a cat... here's the way I just posted about:


:%s/[A-Z]/\L&/g

Likewise for upper case:


:%s/[a-z]/\U&/g

I prefer this way because I am using this construct (:%s/[pattern]/replace/g) all the time so it's more natural.