Which shortcut in Zsh does the same as Ctrl-U in Bash? - 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.

Related

How to get Bash's revert-line in zsh

Since macOS changed to zsh as default, I try to update my keybindings for it.
In bash I could use the following command:
bind '"\C-a": revert-line' # Revert/resets the changed history line while you are on it with the the cursor
I do not find any function like that on zsh.
bindkey "^a" what-to-put-here
Do you know how to accomplish it with zsh?
revert-line is a function provided by readline. While, ZSH doesn't depend on readline. ZSH has its own editor in command line called ZLE(ZSH Line Editor).
There doesn't seem to be a reset all function in the ZLE builtins. Correct me if I'm wrong.
undo may be an alternative for you.
undo
Incrementally undo the last text modification. When called from a user-defined widget, takes an optional argument indicating a previous state of the undo history as returned by the UNDO_CHANGE_NO variable; modifications are undone until that state is reached, subject to any limit imposed by the UNDO_LIMIT_NO variable.
bindkey "^a" undo

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.

How to change shortcut for iTerm2 clear lines?

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

Get last argument of last command on ESC-. ZSH Vim mode

I want to have the same function of Bash+emacs_mode on Zsh+vi_mode, when you type ESC+. you get the last argument of the last command under the cursor. How can I get it on ZSH?
You can use the same widget (insert-last-word) in both viins and emacs mode; it just isn't bound to a key by default in viins mode.
Run the following in the current shell (and add it to .zshrc for it to take effect in future shells).
bindkey -M viins '\e.' insert-last-word

Can I make control-u behavior be the same for ZSH as it is for Bash?

In Bash, control-u will clear from the curser to the beginning of the line, and put that text into the paste buffer, which can be pasted with control-y.
In Zsh, it will clear the text, but does not put it into the buffer.
sadness.
This can be done really easily with just two bindkey commands:
bindkey '^U' backward-kill-line
bindkey '^Y' yank
It may be worth noting that at least '^Y' should be bound in the default Emacs keymap.

Resources