6

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 Oct 19 '16 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 Oct 19 '16 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 Oct 20 '16 at 7:52
  • 1
    there is no such event. – Christian Brabandt Oct 20 '16 at 10:03
1

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"
    else
      echo "-"
    endif
    let s:m = m
  endif
endfunction

Start with:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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