I want a movement to jump to the end of a block of code. I wrote a function and I'm trying to onoremap it, but it doesn't work. Here is what I do:
onoremap <silent> } :set opfunc=MovementToEdgeOfBlock(1)<cr>g@
If I do simply:
nnoremap <silent> } :call MovementToEdgeOfBlock(1)<cr>
then the function works as intended. But I need it more as a movement for other commands. So what am I doing wrong?
Here is the function itself (I don't think that the problem is in the function, but anyway):
function! MovementToEdgeOfBlock(direction)
let startLine=line(".")
function! HowManyTabs(line)
let i=0
while a:line[i]==#"\t"
let i+=1
endwhile
return i
endfunction
let startLineTabs = HowManyTabs(getline("."))
echom startLineTabs " tabs"
if a:direction==1
let tabs=HowManyTabs(getline(line('.')+1))
else
let tabs=HowManyTabs(getline(line('.')-1))
endif
while tabs>startLineTabs
if a:direction==1
execute "normal! j"
else
execute "normal! k"
endif
let tabs=HowManyTabs(getline(line('.')))
endwhile
endfunction