How to convert all text to lowercase in Vim

VimText Processing

Vim Problem Overview


How do you convert all text in Vim to lowercase? Is it even possible?

Vim Solutions


Solution 1 - Vim

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

Solution 2 - Vim

  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.

Solution 3 - Vim

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.

Solution 4 - Vim

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

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

Solution 5 - Vim

Many ways to skin a cat... here's the way I just http://www.alecjacobson.com/weblog/?p=459">posted</a> 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.

Solution 6 - Vim

  • 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.

For examples and more info please read this: http://vim.wikia.com/wiki/Switching_case_of_characters

Solution 7 - Vim

use ggguG

gg: goes to the first line.

gu: change to lowercase.

G: goes to the last line.

Solution 8 - Vim

Usually Vu (or VU for uppercase) is enough to turn the whole line into lowercase as V already selects the whole line to apply the action against.

Tilda (~) changes the case of the individual letter, resulting in camel case or the similar.

It is really great how Vim has many many different modes to deal with various occasions and how those modes are neatly organized.

For instance, v - the true visual mode, and the related V - visual line, and Ctrl+Q - visual block modes (what allows you to select blocks, a great feature some other advanced editors also offer usually by holding the Alt key and selecting the text).

Solution 9 - Vim

If you are running under a flavor of Unix

:0,$!tr "[A-Z]" "[a-z]"

Solution 10 - Vim

I had a similar issue, and I wanted to use ":%s/old/new/g", but ended up using two commands:

:0
gu:$

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionksuraltaView Question on Stackoverflow
Solution 1 - Vimuser80168View Answer on Stackoverflow
Solution 2 - VimzoulView Answer on Stackoverflow
Solution 3 - VimKalanidhiView Answer on Stackoverflow
Solution 4 - VimtarkeshwarView Answer on Stackoverflow
Solution 5 - VimAlec JacobsonView Answer on Stackoverflow
Solution 6 - VimAdolfo AbeggView Answer on Stackoverflow
Solution 7 - VimZiyadskView Answer on Stackoverflow
Solution 8 - Vimuser4104817View Answer on Stackoverflow
Solution 9 - VimojblassView Answer on Stackoverflow
Solution 10 - VimshaolinuxView Answer on Stackoverflow