I have tried to use the following

:nnoremap <leader>t :terminal<cr> <c-w>:call term_sendkeys('', "\<lt>c-r>")<cr>

To open a terminal with reverse search waiting for some input, but instead, it writes:

$ ▉

I expected something like this:

(reverse-i-search)`': ▉


If I use (the same keymap without the <cr> at the end):

:nnoremap <leader>t :terminal<cr> <c-w>:call term_sendkeys('', "\<lt>c-r>")

And I press:


It works.

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               +clientserver      +diff              +folding           +langmap           +mouse_dec         +num64             +reltime           +syntax            +title             +wildmenu
+arabic            +clipboard         +digraphs          -footer            +libcall           +mouse_gpm         +packages          +rightleft         +tag_binary        -toolbar           +windows
+autocmd           +cmdline_compl     -dnd               +fork()            +linebreak         -mouse_jsbterm     +path_extra        +ruby              -tag_old_static    +user_commands     +writebackup
+autochdir         +cmdline_hist      -ebcdic            +gettext           +lispindent        +mouse_netterm     +perl              +scrollbind        -tag_any_white     +vartabs           +X11
-autoservername    +cmdline_info      +emacs_tags        -hangul_input      +listcmds          +mouse_sgr         +persistent_undo   +signs             +tcl               +vertsplit         +xfontset
-balloon_eval      +comments          +eval              +iconv             +localmap          -mouse_sysmouse    +popupwin          +smartindent       +termguicolors     +vim9script        -xim
+balloon_eval_term +conceal           +ex_extra          +insert_expand     +lua               +mouse_urxvt       +postscript        +sodium            +terminal          +viminfo           -xpm
-browse            +cryptv            +extra_search      +ipv6              +menu              +mouse_xterm       +printer           +sound             +terminfo          +virtualedit       +xsmp_interact
++builtin_terms    +cscope            -farsi             +job               +mksession         +multi_byte        +profile           +spell             +termresponse      +visual            +xterm_clipboard
+byte_offset       +cursorbind        +file_in_path      +jumplist          +modify_fname      +multi_lang        -python            +startuptime       +textobjects       +visualextra       -xterm_save
+channel           +cursorshape       +find_in_path      +keymap            +mouse             -mzscheme          +python3           +statusline        +textprop          +vreplace
+cindent           +dialog_con        +float             +lambda            -mouseshape        +netbeans_intg     +quickfix          -sun_workshop      +timers            +wildignore
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-cdpF6P/vim-9.0.0749=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -
Linking: gcc -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-
z,now -Wl,--as-needed -o vim -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lsodium -lacl -lattr -lgpm -L/usr/lib -llua5.2 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/us
r/lib/x86_64-linux-gnu/perl/5.34/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.10/config-3.10-x86_64-linux-gnu -lpython3.10 -lcrypt -ldl -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthrea
d -lm -lruby-3.0 -lm -L/usr/lib

2 Answers 2


Using term_wait solves the issue, I suppose that the terminal wasn't ready as soon as the keys were sent by vim (in my slow computer).

By default term_wait uses 10 msec, and the problem was the same, with 20 msec <leader>t works fine.

:nnoremap <leader>t :terminal<CR> <c-w>:call term_wait('', 20)<cr><c-w>:call term_sendkeys('', "\<lt>c-r>")<cr>

I would do:

:nnoremap <leader>t :terminal<Cr><C-w>:call term_sendkeys('', "\<lt>C-r>")<Cr>
  • I got, the same result :c Feb 9, 2023 at 18:16
  • 1
    It works for me. What is your version of Vim? I suppose your are running on Linux. Feb 9, 2023 at 18:19
  • 1
    I'm on Windows. I'll try on Ubuntu but I suppose your solution is the good one ;-) Feb 11, 2023 at 16:11
  • 1
    It works, but I don't like having to guess the term_wait msec, hence it's just a quick fix :c Feb 11, 2023 at 16:18
  • 1
    It works for me on Ubuntu 22.04 and Vim 9.0 :-| Feb 11, 2023 at 16:47

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.