In §9 of :h channel is mentioned the legacy vimscript out_cb handler.

let job = job_start(command, {"out_cb": "MyHandler"})
The function will be called with the channel and a message. You would define
it like this: 
    func MyHandler(channel, msg)  

I tried this def OutCb function but got the following message error :

  def OutCb(l: list<any>)
    # echomsg 'OutCb' .. string(l)
    # eval [][0]

  def ExitCb(l: list<any>)
    # echomsg 'ExitCb' .. string(l)
    # sleep 1m
    # source += l
    # echomsg 'Exiting ' .. string(l) .. ' ' .. string(@z)

  jobid = job_start(zip_cmd, { out_cb: OutCb, exit_cb:  ExitCb, mode: 'raw', timeout: 1200000 } )

Error message:

  This is a valid directory .
  Jobid: process 14328 run
  Press ENTER or type command to continue
  E118: Too many arguments for function: <lambda>4

How to port and deal with this in vim9 script that seems to have only one argument?

  • 2
    out_cb/exit_cb take 2 arguments not 1 list
    – Mass
    Feb 27, 2022 at 14:36

1 Answer 1


This is official answer of Bram Moolenaar, hope this can help someone. 😊

In Vim9 script the type of the arguments is checked. That helps you writing correct functions, and once written it is easier to read back. It does require a bit of extra text.

Here is an example that will help you:


# Create a channel log so we can see what happens.
ch_logfile('logfile', 'w')

var shell_job: job

# Function handling a line of text that has been typed.
def TextEntered(text: string)
  # Send the text to a shell with Enter appended.
  ch_sendraw(shell_job, text .. "\n")

# Function handling output from the shell: Add it above the prompt.
def GotOutput(channel: channel, msg: string)
  append(line("$") - 1, "- " .. msg)

# Function handling the shell exits: close the window.
def JobExit(job: job, status: number)

# Start a shell in the background.
shell_job = job_start(["/bin/sh"], {
                         out_cb: GotOutput,
                         err_cb: GotOutput,
                         exit_cb: JobExit,

set buftype=prompt
var buf = bufnr('')
prompt_setcallback(buf, TextEntered)
prompt_setprompt(buf, "shell command: ")

# start accepting shell commands

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.