In terminal.txt, there is description about terminal-api, but it seems not to give a example to show how the message is send from terminal to vim function Tapi_..., is there some examples for the usage?

1 Answer 1


Section :help terminal-api includes a thorough description of the API and also an example function:

function Tapi_Impression(bufnum, arglist)
  if len(a:arglist) == 2
    echomsg "impression " . a:arglist[0]
    echomsg "count " . a:arglist[1]

Then inside a :term you can call this function by sending a special sequence starting with <Esc>]51;, then including a JSON encoded list (whose first element is the string "call", the second is the name of the function to call and the third a list of arguments to pass), finally followed by a <07>, which is the ASCII character with code 07, which is the "bell" control character.

In a shell (such as bash), you can use echo -e to have it interpret special sequences, and then \e to issue an <Esc> character, and \a for a "bell" which has ASCII code <07>. Putting it all together:

$ echo -ne '\e]51;["call", "Tapi_Impression", ["play", 14]]\a'

This will call the Tapi_Impression function, which in turn will print the following message (also available in :messages):

impression play
count 14

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.