In one can do the following:

bind -x '"\C-l":ls'

to map Ctrl+L to external (ie. system's rather than function)

ls command to list directory contents.

How to do the same in , and preferably with Alt (\M-l?)

instead of Ctrl as it is seemingly already bound to clear to clear the screen.

2 Answers 2

% namingthingsishard () { echo; ls; zle redisplay }
% zle -N namingthingsishard                  
% bindkey '^l' namingthingsishard                  

This binds control+l because I don't know what \M-l generates for you; running read -r and then mashing keys might show something suitable to use with bindkey, or run bindkey with no arguments to show what is already set. For more information on bindkey and widgets, see zshzle(1).

  • 1
    any idea about unbind?
    – John D
    Mar 9, 2022 at 0:18

CTRL+L to run 'ls'

bindkey -s "^L" 'ls^M'

You must log in to answer this question.