I have a simple custom operator, it echoes
v:register, it's mapped to
,f. After reading this, i creat it like this :
function! s:foo(type,...) echo v:register endfunction function! s:setupOpfunc(func) let &opfunc = a:func return 'g@' endfunction nnoremap <expr> ,f <sid>setupOpfunc('<sid>foo')
It wors fine on built in textobjects, e.g.
But it doesn't work on custom textobject. Assume i have this simple custom text object:
vnoremap ix iw " I know you can map to `iw` directly, but that's not the point of this problem. onoremap ix :normal vix<cr>
I think it doesn't work because
:normal ... erased
v:resiter. I tried to use
onoremap <expr> ... to create
omap for textobject, but :h map-expression says
:normal( needed to visually select text object ) is blocked during it's expression evaluation.
Built in operator has no this kind of problem
"xyix happily copy word into register
One crude way i know to make this work is to use some global variable:
function! s:setupOpfunc(func) let g:__opfunc_rgister = v:register ... endfunction
But it doesn't feel right, are there any other ways to make this work?