1

I am trying to handle events of nvim using nvim_subscribe() API via RPC. For instance, calling nvim_subscribe('CmdLineEnter').

I am not sure the specification of this API exactly, but I imagine that the notification will be call back to the client when the 'CmdLineEnter' event occurs in nvim. Is my understanding correct?

1 Answer 1

1

I found a solution to subscribe to events.

First monitor the event you want to subscribe with autocmd, and emit the event I defined myself by using rpcnotify(). For instance, define an autocmd in init.vim as below:

autocmd CmdLineEnter * call rpcnotify(0, 'mymethod')

Or define it by nvim_command(above autocmd) via RPC.

Then, after execute nvim_subscribe('mymethod'), nvim notifies mymethod event to the client via RPC whenever CmdLineEnter event happens.

2
  • What does nvim_subscribe do in this case / why do you need to invoke it? Shouldn't you just get the notification from rpcnotify without it when the CmdLineEnter autocmd is triggered?
    – Kvass
    Feb 18, 2021 at 4:23
  • 1
    I did some digging here. If you rpcnotify a specific channel, subscriptions do not matter. If you rpcnotify with channel 0 (broadcast), only channels that have subscribed to the event will receive it.
    – Kvass
    Feb 18, 2021 at 5:00

Your Answer

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

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