1

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

1
  • Did this answer work. If so the tick the ✓. Commented Dec 29, 2017 at 16:08

1 Answer 1

2

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).

1
  • Small addition: If you want to unset magic only for one expression, you can just add a \v, \V, \M inside your expression :)
    – Bog
    Commented Dec 4, 2023 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .