Hervey
Hervey

Reputation: 33

why this vim function can't work but run it as a cmd

It have this code:

autocmd BufWritePre,FileWritePre *vimrc  call LastMod()
fun LastMod()
    let l =  min([line('$'), 8]) 
    exe "1," . l . "g/Modified Times:/s/\d\+/\=submatch(0) + 1/"
endfun

When I run it as a cmd, it works:

1,8g/Modified Times:/s/\d\+/\=submatch(0) + 1/

But doesn't work in the function. Why?

Upvotes: 2

Views: 43

Answers (1)

Luc Hermitte
Luc Hermitte

Reputation: 32976

You're using double quotes instead of simple quotes. All your backslashes need to be doubled. Or better yet, use single quotes.

See: https://vi.stackexchange.com/questions/9706/what-is-the-difference-between-single-and-double-quoted-strings

PS: it would have been better to describe what you were observing. Luckily, your mistake is a recurring one.

Upvotes: 3

Related Questions