How to change shortcut for iTerm2 clear lines? - macos

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.

Ctrl-L or "form feed" is part of the ANSI/VT100 protocol (http://wiki.bash-hackers.org/scripting/terminalcodes), it's not specific to iTerm2.
Your best best is to use Applescript to send Ctrl-L to the terminal when Cmd-L is pressed.

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'.

Related

For further research: terminology about manipulating command before hitting RET in terminal

I just found out in zsh if I have a variable, namely abc="cba", and if I type echo ${!abc} and pressing enter, it doesnt go as command but instead open new prompt below with expanded variable echo ${abc="cba"}.
And probably included that powerful zsh plugin that let us automatically insert sudo just by double tapping Esc.
So for further studying and probably opening new possibilities, what is the right terminology about that typed-command-but-not-entered manipulation?
Thanks...
Those seem to be unrelated. The first is zsh asking you to verify history expansion. The second is a ZLE (Zsh Line Editor) widget with a keybinding to modify the current command line. You can see what this ZLE widget looks like in oh-my-zsh the source code.

ZSH shell and CLion/PyCharm integration, movement around terminal

I'm trying to use zsh in the CLion terminal window (changed my shell to /bin/zsh)
But when I try to move around using Ctrl + Left, Ctrl + Right, Ctrl + E... I get the literal characters D, C and Ctrl + E opens the "Recent files" UI
Is there any way around this? I'd like to use the movement keystrokes as I can with bash.
Tempoz,
Check out the offical Zsh Line Editor doc and the Z-Shell Line Editor guide for tons of detail.
To start, you can see your current mappings by typing bindkey at your prompt. There are two start modes: emacs [default], and vi. If you want to use vi mode, add this to your ~/.zshrc
bindkey -v
and source it (or restart your shell, or restart your IDE). Check out how the bindkey output has changed.
If you decide you want to change or augment your key mappings, use bind in your ~/.zshrc to reassign, or add to your key map.
# Example key binding change
# bindkey key-sequence editor-command
bindkey '^Z' vi-kill-line
You will also probably want to fix your $PATH - all the JetBrains products do it incorrectly. See this answer: https://stackoverflow.com/a/51006003/1089228

zsh shortcut 'ctrl + A' not working

I recently switch from bash to zsh shell. To be more precise, the oh-my-zsh
Very nice, but the shortcut I most often use; jumping to the beginning/end of the line doesn't work anymore. From the docs it should be
ctrl + A --> beginning
ctrl + E --> end
However, when I do that I get the following
$~> my-command
$~> my-command^A # did a ctrl + A here
Although I see this working by everybody else, on my system something seems to be different. Any suggestions what that might be ?
If you're wondering why this happened: You likely have $EDITOR or $VISUAL set to vi/vim which made zsh default to the vi keymap which doesn't use ctrl+a for moving the caret.
Adding bindkey -e to ~/.zshrc will restore the old behavior (emacs keymap).
you don't have to config the Ctrl+A behavior if you use default keymap (emacs keymap). It does what you are expecting.
However if you set your zle to use vi keymap, you have to define the keybind for vi-beginning-of-line. same for Ctrl+E.
So check which keymap did you set in config. If it was vi, try pressing ESC then ^ and $ should do what you want.
zsh .zshrc
bindkey "^A" vi-beginning-of-line

Which shortcut in Zsh does the same as Ctrl-U in Bash?

In Bash, when I am typing a command, I press Ctrl+U, all characters from the beginning of the line to the cursor are going to be removed. However, in zsh, if I pressed Ctrl+U, the whole line is gone.
How to do the same in Zsh as in Bash?
It sounds like you'd like for Ctrl+U to be bound to backward-kill-line rather than kill-whole-line, so add this to your .zshrc:
bindkey \^U backward-kill-line
The bindkey builtin and the available editing commands (“widgets”) are documented in the zshzle man page.

Enable zsh using 8th bit as Meta without warning

In my quest to configure my shell to work exactly how I want it with respect to the alt/meta key I am having some trouble. Recently I added "bindkey -m" to my .zshrc and now whenever I start a zsh shell (ie open a terminal window) I get this error "warning: `bindkey -m' disables multibyte support".
Now since I don't care much about multibyte support atm, is there a way I can disable just this warning? Even better would be a way to use 8th-bit meta as well as multibyte. Also note that this happens on a clean zsh install on 4.3.9 and 4.3.10
My reasoning for wanting bindkey -m
vim: alt mappings (my own personal commands/mappings)
zsh: alt mappings (such as Alt-. to recall the last argument of the previous command)
emacs: alt mappings (lots of built-ins)
So, is there any way to disable this warning or otherwise accomplish what I'm trying to do?
You can sweep the message under the rug:
bindkey -m 2>/dev/null
Don't mappings to escape (\[) also work for Alt for you? Alt-. works for me, for example, by default.
Also, unless you're talking about the command line editing modes, vim and emacs handle their own keyboard mapping. Settings in zsh won't affect them.

Resources