I’m trying to replace all occurrence of hello(...) by hello[...]
I tried things like %s/hello\((.*?)\)/hello\[$1\]/ without any success
Any help pls ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s Perl syntax, not Vim. In Vim regular expressions, at least by default, parentheses match themselves and backslashed parentheses capture – the opposite of Perl. Also, Vim doesn’t understand the non-greedy modifier
?, and capture groups are interpolated with\n, not$n. Try this:Alternatively, you can use the
\v(“very magic”) modifier to make the behavior with respect to special characters and backslashes more Perl-like, though it doesn’t make Vim understand*?or change its interpolation syntax:Also, note that you don’t need backslashes on the square brackets in the replacement text – the right hand side of a substitution command is not a regular expression, so you don’t have to worry about most of the characters that are special in one. Pretty much only the backslash itself is special, and can be used to include capture groups or a literal instance of itself or the delimiter.