Option key command editing shortcuts

Dec 20, '02 08:02:46AM

Contributed by: Xeo

When in Terminal, the option key provides you with many shortcuts. Here is a list of these shortcuts that I've found.

For all these shortcuts, hold the Option key and press the character given. When speaking of multiple commands, I mean something like:

 % cd ~/Documents; ls -al; mv *.txt ~/Documents/some_dir
where each phrase is its own command on the same line. Many of these shortcuts are for jumping between these and modifying the current command string. None of these hints deal with commands in the history (such as pressing up and down).

[Editor's note: At first, I couldn't make any of the following shortcuts work. After looking at the prefs for a bit, I noticed that I had enabled "Use option key as meta key" in the Emulation tab of the Display preferences. Once I disabled that, these keys worked as described ... on my G4. On my iBook, with the exact same settings in the prefs (on all tabs), I get accented international characters. Both machines have the same US keyboard showing in the menubar and the same character encoding, so I'm stumped as to what's causing the different behaviors - any ideas? In addition, I believe the following are somehow related to the standard "bindkey" commands, but some of them don't seem to correlate with the "bindkey" defintions - anyone with more expertise care to offer an explanation?]

Once you've got a line with multiple commands on it, then Option- and the following keys will generate (probably?) the described behaviors. In my examples, the red letter is where the cursor is at, and the "aaaa; bbbb; cccc; dddd" is used to represent any string of multiple commands.

------- "a" -------
First press goes to next command and capitalizes the letter the cursor was at. Second press goes to the end of the line and capitalizes the letter the cursor was at.

Before first press:
% aaaa; bbbb; cccc; dddd

After first press, before second press:
% aAaa; bbbb; cccc; dddd

After second press:
% aAaa; Bbbb; cccc; dddd cursor at end of line

------- "c" -------
Same as "a" but jumps to next command with each press instead of the end of the line.

------- "d" -------
Deletes every other previous command from where the cursor is at (best explained with examples).

Before first press:
% aaaa; bbbb; cccc; dddd cursor at end of line

After first press, before second press:
% aaaa; bbbb; dddd

After second press:
% bbbb; dddd

Second example:

Before first press:
% aaaa; bbbb; cccc; dddd

After first press, before second press:
% aaaa; cccc; dddd

After second press:
% aaaa; cccc; dddd

------- "e" -------
Strange effects. Appears to jump backwards but is doing something else also. Experiment on your own.

------- "f" -------
Jumps to end of each following command without modifying the command.

Before first press:
% aaaa; bbbb; cccc; dddd

After first press, before second press:
% aaaa; bbbb; cccc; dddd

After second press:
% aaaa; bbbb; cccc; dddd

------- "g" -------
Jumps to beginning of each command without modifying the command.

Before first press:
% aaaa; bbbb; cccc; dddd

After first press, before second press:
% aaaa; bbbb; cccc; dddd

After second press:
% aaaa; bbbb; cccc; dddd

------- "j" -------
Appears to do the same as "d"

------- "l" -------
Appears do to the same as "g"

------- "m" -------
Goes to beginning of command, then the following character is inserted five times. Using the arrow key as the following character will move the cursor five places. Hitting a letter will insert that letter five times.

------- "o" -------
Appears to do the same as "a"

------- "r" -------
Appears to do the same as "g"

------- "s" -------
Capitalizes the character it is on, then duplicates the current command.

Before first press:
% aaaa; bbbb; cccc; dddd

After first press, before second press:
% aaaa; bbbb; cccc; DdddDddd cursor at end of line

After second press:
% aaaa; bbbb; cccc; DdddDdddDdddDddd cursor at end of line

------- "t" -------
Appears to do the same as "g"

------- "v" -------
Appears to do the same as "d"

------- "x" -------
Appears to do the same as "d"

------- "y" -------
Inserts a backslash "" character.

------- ">" -------
This doesn't modify the command but just list the contents of the CWD.

------- "0" - "9" -------
All seem to go back a command on each press like "g" except for "2" which seems to also list the contents of the CWD, "5" which acts like "d," and "7" which jumps to the previous command on the first press and to the beginning of the line on the second.

--------------

I hope this list is useful to someone. Please feel free to correct me or add any new findings.

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20021220050246545