Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Alternative delete a 'word' shortcut in Terminal Apps
Often times I'm in Terminal and I recall a command using the up-arrow. I then want to delete a portion of this command and replace it. Hitting the Delete multiple times is annoying at best.

The bash shell offers limited Emacs-style command line editing, with which one can delete a word using the sequence Escape-Control-H. While this works, it's awkward because it requires lots of movement with the left hand, and is difficult to do repeatedly.

It occurred to me that the Delete key is probably sending out a Control-H, so I tried the sequence Escape-Delete instead, using my left hand for Escape and my right hand for Delete. It worked, and was very easy to do repeatedly. And even if you miss the Escape, you still get the Delete, so no damage is done.
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[15,034 views]  

Alternative delete a 'word' shortcut in Terminal | 17 comments | Create New Account
Click here to return to the 'Alternative delete a 'word' shortcut in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Alternative delete a 'word' shortcut in Terminal
Authored by: fguilleme on Aug 31, '07 07:42:33AM
I use Control-W. It's one hand but two fingers... Combined with Control-R to search the history it's pretty convenient. But bash offer a plenty of key bindings. Use bind -p to get a list

[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: nvdingo on Aug 31, '07 07:49:44AM

Or just open the window settings panel, choose the keyboard section and enable 'use option key as meta key'

this allows the use of option instead of esc
a little more convenient
meta-d will delete the word forward of the cursor by the way.



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: robleach on Aug 31, '07 08:47:37AM

Cool. Most of these commands are working in tcsh too. I particularly like esc-delete, esc-d, and control-w. I've put those on a sticky until I have them memorized. I was disappointed that `bind -p` didn't come up with anything (command not found). Is there a tcsh analog to that command? I'd like to learn more keyboard commands. Also, are there any unforseen consequences of using the option key as a meta-key? What's the downside? Option-click still seems to work to position the cursor with the meta-thing checked.

Rob



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: fguilleme on Aug 31, '07 09:07:07AM
with tcsh you can use bindkey tcsh also offer a extensive list of key bindings. I don't remember (I switched to bash a few yars ago) but it was quite nice. I particulary miss the -p history completion. But if you want to lean further type the magical command man tcsh

[ Reply to This | # ]
bash vi mode
Authored by: googoo on Aug 31, '07 08:48:01AM
For those of you who prefer vi, you can set bash to use vi-style editing by adding the following line to your .bashrc file.
set -o vi

Then you delete a word by pressing escape followed by dw. When you are done, enter i to go back to insert mode so you can continue typing your command.

-Mark



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: ghay on Aug 31, '07 09:57:09AM

I can confirm esc-del also works in tcsh



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: badcarl on Aug 31, '07 10:04:24AM

System Preferences, Keyboard & Mouse, Modifier Keys, map Caps Lock to Control. If you use emacs style navigation (and never use caps lock), you'll be in heaven.



[ Reply to This | # ]
bindkey also works with zsh
Authored by: dzurn on Aug 31, '07 11:44:25AM
The bindkey command also works in zsh.

This is a shell built-in command but you can get help for the command with man zshzle.

bindkey -e will turn on the emacs bindings. Other keymaps are available, or roll your own.

---
Madness takes its toll.
Please have exact change.

[ Reply to This | # ]

How to move cursor a line at a time?
Authored by: steresi on Aug 31, '07 02:00:33PM

I often have a long command on the command line and would like to move through it by "lines" (say, about 130 characters). If I have a command that spans 3 or 4 lines in Terminal, is there any way to move right to the middle of it, or move back 100 characters at a time?



[ Reply to This | # ]
How to move cursor a line at a time?
Authored by: boxcarl on Aug 31, '07 02:28:23PM
How to move cursor a line at a time?
Authored by: brettmjohnson on Sep 01, '07 01:34:49PM
... is there any way to move right to the middle of it, or move back 100 characters at a time?"

Bash uses readline as its command line editor. Nearly every readline command may be preceded with a numeric multiplier argument. For instance, M-4 M-f moves forward 4 words, and M-100 C-b moves backward 100 characters.

As mentioned previously, if you don't have a Meta key mapped, use Esc instead.

[ Reply to This | # ]

How to move cursor a line at a time?
Authored by: steresi on Sep 03, '07 10:47:41PM

Excellente!!!



[ Reply to This | # ]
How to move cursor a line at a time?
Authored by: bryanc on Sep 06, '07 04:14:42PM

If your commands are that long, you might also find it useful to edit the current command-line in your default text editor. Just press C-x C-e.

When you quit the editor the command is executed as normal.

(You can change the editor used by setting the $EDITOR environment variable, it uses emacs by default I think).

If you use vi-mode for the shell, the keybinding is esc-v. (or just v if your not in insert mode).



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: taojian on Sep 02, '07 04:20:45AM

This works nicely, but if I held down the esc key a little too long, it started behaving oddly. It looked like it was doing some kind of complete-command-and-run function: when I was experimenting with `ls` it completed a directory name (like tab usually would), and then ran the ls command repeatedly, until I let up on the esc key. I tried it with an empty command line and it asked if I wanted to display all 1245 possibilities, which I didn't.

Does anyone have a more precise explanation for what holding down the esc key is doing?



[ Reply to This | # ]
Alternative delete a 'word' shortcut in Terminal
Authored by: fguilleme on Sep 02, '07 06:32:40AM

Actually M-C-[ is bound to complete! And since Meta returns escape it is identical to C-[ C-[ so two times escapes.
Have a look to man readline.



[ Reply to This | # ]
powerbook G4 not charging
Authored by: Jdogg on Sep 02, '07 05:07:18PM

hi there,

I have a problem with my powerbook G4. It is 3 years old and i have i new battery in it. All of a sudden it has just decided to not charging. I have tryed a number of things such as reseting the PMU, PRAM and rest all in Open Firmware. Took the battery out and put it back in lots of times, changed power surplyes and battery but, it still stays at 0%. What do i do next?
If any one can help please do so.

Thanks
Jdogg



[ Reply to This | # ]
powerbook G4 not charging
Authored by: TvE on Sep 03, '07 01:28:26PM

Yeah - open a new thread, your problem is probably not related to erasing words in BASH… ;-)



[ Reply to This | # ]