20

In Linux I'm used to press Ctrl-Backspace to delete the last word but I don't know how to do it in Bash terminal.

In OS X I use Alt-Backspace to do the same thing.

Is there any way of making Bash recognize the Ctrl- or Alt-Backspace key combination to delete last word?

In Linux I use terminator as terminal emulator, in OSX I use iTerm2.

slhck
  • 235,242
licorna
  • 541

6 Answers6

35

You can always use Ctrl-W. It deletes the word before the cursor and works in every Bash.

See here for a list of Bash keyboard shortcuts.

slhck
  • 235,242
6

You just need to set Option as Meta key in iTerm's preferences (Profiles » Keys).

backward-kill-word is bound to Meta-Rubout (i.e. Opt-Backspace) by default.

The same option exists (albeit less flexible) in Apple's Terminal.app.

Daniel Beck
  • 111,893
4

You can create a file .inputrc in your home directory and add this content inside:

"\C-h": backward-kill-word
Sel
  • 263
2

As some have mentioned, this may also depend on your terminal emulator. For example in KDE's Konsole, you can define the behavior of Ctrl+Backspace in the key bindings settings of the profile:

Set Backspace+Ctrl to the output \E\x7f (default \b)

Konsole Key Binding List

quazgar
  • 804
2

In terminator you can use the following "plugin", along with

[keybindings]
    kill_word = <Control>BackSpace

in your config file. This will map Ctrl-Backspace to ESCDEL, another shorcut to delete last word.

0

You can just use Alt-DEL instead of the normal Strg-DEL.