I can't seem to figure out how to set a variable equal to the number of matches in a file.
I have tried this
let a=execute('%s/<++>//ne')
but it won't work (throws this error:
Error detected while processing function myfunctions#Tab:
line 2:
E523: Not allowed here
). I want a variable with the number of matches for a regular expression and I can't seem to find a way to use the execute() function with the substitute command. (execute('%s/test//ne') throws an error too).
EDIT: I am trying to run this inside a function that is called as an <expr> mapping. The full function body is this (control characters properly inserted):
function! myfunctions#Tab()
let a=execute('%s/<++>//ne')
if a > 0
return "/<++>^M:noh^Mc4l"
else
return "^I"
endif
endfunction
The goal is to insert a tab if the pattern <++> doesn't exist, and if it does, then find it and replace it. I mapped it like this:
inoremap <expr> <tab> myfunctions#Tab()