2

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:

^R
$ ▉

I expected something like this:

(reverse-i-search)`': ▉

Note:

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:

<leader>t<cr>

It works.

version
:ver
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
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 -
Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
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 Answers2

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>
1

I would do:

:nnoremap <leader>t :terminal<Cr><C-w>:call term_sendkeys('', "\<lt>C-r>")<Cr>
Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37