I'd like to make a plugin to display currently pending keys while in operator-pending mode. As the first part of that, how would I register an autocmd to run when operator-pending mode is entered? I'm using neovim, so I'm totally cool if it only works there.

  • 4
    Have you seen what :set showcmd displays? What do you intend to show in addition to that?
    – jamessan
    Commented Oct 19, 2016 at 20:17
  • Huh! of course it already exists. I've been getting so addicted to vimscript that I didn't think to check. I do want to go further, though - I'd like to preview changes that will be caused by repeating commands, so it'd still be cool to know if there's a way to get that event.
    – lahwran
    Commented Oct 19, 2016 at 20:55
  • 1
    :h autocmd-events gives you all of the available autocommand events, and I don't think there is one for entering operator pending mode. But maybe you could do something with some operator pending mode mappings: :h omap-info
    – statox
    Commented Oct 20, 2016 at 7:52
  • 1
    there is no such event. Commented Oct 20, 2016 at 10:03
  • 1
    Now there is! (as at 8.2.3430, (sep 12 2022)) au ModeChanged *:no* {cmd}
    – husB
    Commented Jan 8, 2023 at 15:20

2 Answers 2


Well, you could always poll Vim:

let s:m = ''

function! MyHandler(timer)
  let m = mode(1)
  if m != s:m
    if m == 'no'
      echo "operator pending"
      echo "-"
    let s:m = m

Start with:

:call timer_start(250, 'MyHandler', {'repeat': -1})

Not sure if still useful. But for future Google searches...

See h: ModeChanged

  • 1
    Definitely useful, but some some details (say, an example), would make it even better!
    – husB
    Commented Jan 8, 2023 at 15:22

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.