I want to call g@
from a function.
Given an operation:
" Taken from :help g@
function! CountSpaces(type, ...)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
echomsg strlen(substitute(@@, '[^ ]', '', 'g'))
let &selection = sel_save
let @@ = reg_save
endfunction
I want to call it from:
function! my_fun(...)
set opfunc=CountSpaces
normal! g@
endfunction
But it doesn't work, nothing happens. Am I doing something wrong?
my_fun
probably needs an uppercase startg@
needs a motion. Thereforenormal! g@
does nothing. (But, for example,normal! g@$
will work).