I wrote a vim-script function, which allows me to grep a keyword in my project.
function! CustomGrep(...) if a:0 == 0 silent vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp else silent execute 'vimgrep' a:1 '**/*.h **/*.hpp **/*.c **/*.cpp' endif "cope endfunction
Now I want to write another function, which can replace a keyword:
function! CustomReplace(target, newWord) call CustomGrep(a:target) " loop --- how to loop? execute 's/'.a:target.'/'.a:newWord.'/gc' cnext " end loop endfunction
Obviously, I need a loop in the function, which looks like:
let cnt = CustomGrep(a:target) for from 1 to cnt execute 's/'.a:target.'/'.a:newWord.'/gc' cnext endfor
But I don't know how to get the number of the output of
BTW, I know there have been some plugins, such as
EasyGrep, but I still want to make a new one.