How do you convert all text in Vim to lowercase? Is it even possible?
This question is related to
vim
text-processing
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.
I had a similar issue, and I wanted to use ":%s/old/new/g"
, but ended up using two commands:
:0
gu:$
I assume you want lowercase the text. Solution is pretty simple:
ggVGu
Explanation:
If you are running under a flavor of Unix
:0,$!tr "[A-Z]" "[a-z]"
g~
then a movement.gU
then a movement.gu
then a movement.For examples and more info please read this: http://vim.wikia.com/wiki/Switching_case_of_characters
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.
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).
Similar to mangledorf's solution, but shorter and layman friendly
:%s/.*/\L&/g
use ggguG
gg
: goes to the first line.
gu
: change to lowercase.
G
: goes to the last line.
Source: Stackoverflow.com