0

I'm reworking some Fortran code. I need to remove the pattern (*,*) using vim's search and replace function. The following does not work

%s/\<(*,*)\>//gc
%s/\<(*\,*)\>//gc
%s/(*,*)//gc 

the last one only removes the contents between the parentheses and not the parentheses themselves

  • Did this answer work. If so the tick the ✓. – ctrl-alt-delor Dec 29 '17 at 16:08
1

You will have to escape the * as \*. The * is special in regular expressions and means match the previous thing zero or more times.

The substitution in Vim would be

:%s/(\*,\*)//g

If you unset the magic option in Vim, with

:set nomagic

then only the ^ ("start of line") and $ ("end of line") characters have special meaning in regular expressions.

This means that the substitution

:%s/(*,*)//g

would do what you'd like it to do.

Most people do want to have the magic option set though (and it is set by default in Vim).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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