80

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?

Jawa
  • 2,336
  • 6
  • 34
  • 39
Kent
  • 189,393
  • 32
  • 233
  • 301
  • 1
    Actually, this is an Emacs hotkey, not bash. Bash reuses lots of the Emacs key bindings. Some other Emacs key bindings to zsh: https://code.google.com/p/vinipsmaker/source/browse/config/.zshrc?spec=svn846ef53b90527aaab08418755be911b81d4c8552&r=846ef53b90527aaab08418755be911b81d4c8552#78 – vinipsmaker Feb 22 '14 at 18:50

1 Answers1

145

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.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
  • 1
    Zsh doesn't use readline, instead it uses its own zle. So i am gonna customize the keybind. thanks! – Kent Aug 14 '10 at 15:38
  • put this in your $HOME/.zshrc and you should be set after you either run "source $HOME/.zshrc" or you open a new terminal session/window – DevOops Oct 01 '17 at 14:58
  • 1
    ```bindkey | grep backward-kill-line``` should output ```"^U" backward-kill-line``` – woto Nov 28 '18 at 18:55
  • Doesn't work for me : It kills the whole line :( – yPhil Jan 04 '21 at 22:02
  • 1
    @yPhil After adding `bindkey \^U backward-kill-line` to your `~/.zshrc`, open a new terminal window or run "source $HOME/.zshrc" to make your change work~ It works for me. – Onns Jul 09 '21 at 02:19