:h terminal-to-job shows the following example of term_sendkeys()

call term_sendkeys(buf, "ls *.java\<CR>")

Following this, I added the line to .vimrc:

nnoremap <Leader>test :call term_sendkeys(2, "ls *.txt\<CR>")

where 2 is the buffer number.

After :terminal, running the command gives an error message:

E114: Missing double quote: "ls *.txt\
E116: Invalid arguments for function term_sendkeys

But, the command works fine if it is used directly in the command mode.

What am I missing?

1 Answer 1


In a mapping call the line is interpreted slightly differently (focusing on keyboard input)

I would do:

nnoremap <Leader>test :call term_sendkeys(2, "ls *.txt<C-v><CR>")<CR>

The right hand side here is not the code itself but the keyboard sequence needed to input it. Furthermore the <.> construct are interpreted as keyboard input.

Your version was equivalent to:

:call term_sendkey(2, "ls *.txt\^M

The code proposed will lead to:

:call term_sendkey(2, "ls *.txt^M")


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.