Mike
Mike

Reputation: 821

Substitution in vimscript failing

I'm missing something subtle and silly on this. I have a short vim script. In it, I'm trying to do:

s/.*_____.*/\=repeat('=', 78)/

(That's the exact code.)

When I do /\v.*____.* in normal mode, I can successfully find the pattern (more than once). When I do that substition in normal mode, it succeeds.

I'm sure I'm missing something as far as escaping a character somewhere. Please enlighten me!

Upvotes: 2

Views: 123

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172570

A s/ command only covers the current line; this is not what you usually want.

The simplest approach is to use %s/... to process the entire buffer. However, your mapping / command may want to support arbitrary ranges. For that, :call will usually invoke your user-defined function once for each line, unless you define the function that it handles the range itself. See :help function-range-example for details.

Upvotes: 1

Related Questions