June 15, 2010

Vim: search/replace to change cases

The following command will change all upper case words to lower case

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

The list of all special commands:

Replacement part of the S&R has its own special characters which we are going to use to fix grammar:

#
Meaning
#
Meaning
&
the whole matched pattern
\L
the following characters are made lowercase
\0
the whole matched pattern
\U
the following characters are made uppercase
\1
the matched pattern in the first pair of \(\)
\E
end of \U and \L
\2
the matched pattern in the second pair of \(\)
\e
end of \U and \L
...
...
\r
split line in two at this point
\9
the matched pattern in the ninth pair of \(\)
\l
next character made lowercase
~
the previous substitute string
\u
next character made uppercase

No comments:

Post a Comment