1

I'm trying to convert

const std::string &s

to

std::string const & s

and can't seem to get it quite right. This is the regex I'm using:

%s/const \(.\{-}\) &/\1 const &

and the result I'm getting:

std::string const const std::string &s

1 Answer 1

3

Just escape the & with a backslash.

%s/const \(.\{-}\) &/\1 const \&

The & in the replace part inserts the entire matched pattern.

See :help s/\&.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.