To replace second character in each line to r
in vim: :%s/^\(.\)./\1r/
:
:%s/p/r/
replace patternp
withr
for all lines (because of%
);^
start line;\(
start a group;.
any character (the first in this example);\)
end the group;.
any character (the second in this example);\1
back reference to the first group (the first character in this example);r
replacement text.
To swap two first characters: :%s/^\(.\)\(.\)/\2\1/
.