I'm new to zsh and am trying to bind a key sequence to a function with the following in my .zshrc:
say_hello(){ echo "hello" } zle -N say_hello bindkey '^Y' say_hello Pressing Ctrl-Y will call the function and I'll see "hello" printed to the terminal but after I need to press Enter again before I'm given another zsh prompt. Calling the function by just typing in say_hello at the zsh prompt and pressing Enter does what I want - I see hello printed and then I'm given another zsh prompt. How can I get this behavior when binding the function to a key sequence?
Above is a simple example, really the function I'm trying to write is below:
my_cd() { if [[ "$#" -ne 0 ]]; then cd $(autojump $@) return fi dir_to_cd_to=$(fasd_cd -dl | fzf --height 40% --reverse --inline-info) # above isn't so important - dir_to_cd_to could be obtained in any way cd "$dir_to_cd_to" } zle -N my_cd bindkey -v '^Y' 'my_cd'
^Yor just to insert text in your commandline?echocommand in the example here to illustrate the behavior I don't understand.zshis already waiting for your input; you don't need to hit Enter (causing the prompt to be redisplayed) before typing your next command. The output simply wrote "hello" and a newline to the terminal in the same place where your input would have been echoed by the terminal.print -zinstead, which will write directly to the input buffer as if you had typed text instead. That might be an alternative to havingzlecall a function "out of band", so to speak.