Little Shell Trick

I've just learned a nice little trick in the OpenSolaris shell - to move one word left you can press Alt-B and to move one word right you can press Alt-F. Make sure to disable the shell top menu (using preferences), to avoid opening the File menu on Alt-F instead. Hmm I've been wondering during all my demos how to move faster inside the command line - this is it :)
Comments:

Thx

Posted by muhabbet on March 15, 2009 at 03:13 PM GMT #

There are a few of these for bash(1). Ctrl+a goes to the beggining of the line, ctrl+e to the end, ctrl+d erases a character/digit, ctrl+r searches the history, ctrl+w removes a word, ...

Posted by Rafael on March 15, 2009 at 03:30 PM GMT #

It's just the same as in Emacs.

Posted by Thommy M. on March 16, 2009 at 12:22 AM GMT #

Thnks dude.

cheers,
Sourav Mohanty

Posted by Sourav Mohnaty on March 16, 2009 at 12:49 AM GMT #

Just as Thommy said, they are the Emacs keys.
So iso ALT-F or ALT-B I use META-F and META-B. On my laptop the META key is the escape-key.

One can switch between 'EMACS' mode and 'VI' mode by issuing the command:

set -o emacs (for emacs mode)
set -o vi (for vi mode)

Posted by Enno on March 16, 2009 at 06:42 AM GMT #

Within bash I do:

set -o vi

Then:

ESC+K -> Previous command line
ESC+/whatever -> Search "whatever" in the command line history
ESC+b -> Move backwards a word
ESC+w -> Move forward to the next word

And many other vi-like key bindings that don't fit within this comment box.

Posted by Antonio on March 16, 2009 at 11:45 AM GMT #

Some seems to like to make life harder than it is... ;-)

Posted by Thommy M. on March 17, 2009 at 04:32 AM GMT #

You can also map 'forward-word' and 'backward-word' in your inputrc, which saves you from having to care about which terminal app you're using. I use Ctrl+arrows, which is common in default Linux inputrc's.

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\\e[1;5C": forward-word
"\\e[1;5D": backward-word
"\\e[5C": forward-word
"\\e[5D": backward-word
"\\e\\e[C": forward-word
"\\e\\e[D": backward-word

Posted by robc on March 19, 2009 at 07:58 PM GMT #

Hopefully OpenSolaris will provide some reasonable default inputrc.
This is tracked by http://defect.opensolaris.org/bz/show_bug.cgi?id=3090.

Posted by hnhn on April 19, 2009 at 05:02 AM GMT #

Quick question though: how do I disable the shell top menu (using preferences)? It's always been a big annoyance for me in GNOME that alt+f opens the "File" menu and doesn't move forward one word in BASH like it should.

Usually you guys are so good about showing screen-shots for everything ;-)

Posted by system5 on August 04, 2009 at 09:50 PM GMT #

thanks..

Posted by cet on September 11, 2009 at 02:03 AM GMT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

The Observatory is a blog for users of Oracle Solaris. Tune in here for tips, tricks and more as we explore the Solaris operating system from Oracle.

Connect with Oracle Solaris:


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today