Quickly repeat a single character in Terminal

Sep 07, '04 08:50:00AM

Contributed by: Netzach

In the Terminal, if you press and hold Option, then type a few numeric keys, then press a character, the result is that the character will be repeated that many times. For instance:

Option [hold] and 10, followed by K will result in KKKKKKKKKK. This works in both the tcsh and bash shells. I can't see why this would be handy, but it is probably something not that many have heard of.

[robg adds: The Option key in this hint is also called the Meta key in Unix. Netzach must have set the "Use option key as meta key" in the Keyboard section of Terminal -> Window Settings; otherwise, the option key and a number will show something like \302\241 in the Terminal. The advantage of using Escape is that you can hit and release the key; you don't need to hold it down. Yes, this is a basic Unix hint, but please understand, many of us (myself included!) are new to the whole Unix thing!

The Meta key is used for a bunch of stuff in Unix, and in the Emacs text editor in particular. Meta-b and Meta-f, for instance, jump back and forward a word at a time. Meta followed by numeric keys, though, enter this "text repeat" mode -- you're supplying an 'argument' for how many times you want the next character to repeat (Unix vets, I apologize for any mis-language in the above explanation!). You can see this if you wait before typing a character; you'll see (arg: 10) until you hit the next non-numeric key.

Why might this be useful? It's not particularly useful in the shell. But if you write code and use Emacs, you can use this trick to input a long comment separator in a hurry. For a PHP comment, for instance, type /, then Option-75 (or Escape), then * followed by a closing /, and you've got a 77 character comment divider.]

Comments (5)


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