Ctrl + l
is the default shortcut for clear lines in iTerm2, I want to change it to Cmd + l
, but can't find this action:
BTW I'm using zsh.
This is an zsh binding is not an iTerm binding. Ctrl+l is the default binding for the clear-screen
widget in zsh. The fact that it also works in bash (and maybe other shells) is merely convention. In bash - or rather readline, bash's command line editor - it is the default binding for a command that is also named clear-screen
.
Generally, you can change a key binding in zsh with the command bindkey KEYSEQUENCE WIDGET
. Unfortunately not all modifiers might be supported by iTerm2 for use with the shell. You can test, whether it is supported by running cat -v
and then pressing the desired key combination. If Cmd+l is supported, than the output shown should be more than just "l
". If it something more or other than just "l
", then you can use the output to bind it. For example if cat -v
shows "^[l
" than you can bind it with bindkey '^[l' clear-screen
and if you want to remove the default binding, you can do so with bindkey -r '^l'
.