I'm trying to redefine my inner and outer line text objects so that they don't change gv. First I had

onoremap <silent> il :<C-u>normal! $v^<CR>

I changed it based on Using visual mode without changing gv

onoremap <silent> il :<C-u>let lastSelectionStart = getpos("'<") \| let lastSelectionEnd = getpos("'>") \| execute "normal! $v^" \| call setpos("'<", lastSelectionStart) \| call setpos("'>", lastSelectionEnd)<CR>

But it doesn't seem to have had the intended effect

1 Answer 1


I don't think it is possible within the operator-pending mode mapping.

The whole right-hand side of an operator-pending mode mapping is meant to visually select the area on which you want to operate. Said another way, the visual area on which the operator is going to operate is only defined after the whole RHS of the mapping has been executed.

This means that restoring '< and '> at any point in the RHS happens before the desired visual area is actually defined, and thus that the final '< and '> override whatever you set within the RHS.

It should be feasible by storing '< and '> before getting into operator-pending mode and restoring them after the operator+motion combo, but that would mean overriding each and every possible combo with a wrapper… which doesn't sound like a good idea at all.

Maybe there is a better approach?

  • I guess gv could be remapped to restore and use the old '<, if visual mode has not been used in-between... which would require remapping visual mode entry keybinds too?
    – minseong
    Apr 22, 2023 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.