Wednesday, February 8, 2012

Cool vim trick.

I have always wanted to be able to replace a word in vim with matching case: if the word to be replaced was capitalized, have the replacement text be capitalized, and vice versa. Well now I can:


%s/\v(l|L)eft/\=(submatch(1) == "L" ? "R" : "r") ."ight"/

sub-replace-expression can be used for lots of other cool techniques too.