Artificial intelligent assistant

How to write into the actual editing buffer I want "ls" to be written, but not executed, by stroking `Control`+`r`. I'm using the following code, but it writes the command into the buffer that will be used to execute _after_ hitting `Enter`. I would like it to be written straightforwardly in some way, but I don't know how: _prefill() { print -z "ls" } zle -N _prefill bindkey '^r' _prefill

In widget functions, the editing buffer is exposed in the `$BUFFER` (whole buffer) and also `$LBUFFER` and `$RBUFFER` (the part of the buffer left and right of the cursor respectively). See `info zsh BUFFER`¹ for details. So here, you'd do:


_prefill() LBUFFER+=ls


`print -z` is to prefill the buffer for the next command so is typically used _outside_ of zle widgets.

* * *

¹ you may need to install a `zsh-doc` package or equivalent as not all systems install the zsh documentation by default (other than the man pages which are not adequate for a manual this size). That documentation is also available online for the latest version. Here's the link for the corresponding `BUFFER` index entry.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e09f12e3286155f9e2facce9ca7d4aed