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

Quickly repeat a single character in Terminal UNIX
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.]
    •    
  • Currently 1.67 / 5
  You rated: 3 / 5 (3 votes cast)
 
[9,159 views]  

Quickly repeat a single character in Terminal | 5 comments | Create New Account
Click here to return to the 'Quickly repeat a single character in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Learn all the capabilities thoroughly
Authored by: krishna on Sep 07, '04 02:04:39PM

Bash and tcsh bindings are almost identical to gnu emacs bindings (bash in particular, since bash and gnu emacs are both tied to Richard Stallman).

Run gnu emacs (type 'emacs' in a terminal window under OS X), read the first screen very carefully, and run the tutorial (takes about an hour, don't skip any steps), you'll be able to get a lot more out of bash (and textedit, or anything that uses the cocoa text editing functionality, for that matter).



[ Reply to This | # ]
Works in zsh too
Authored by: dzurn on Sep 08, '04 04:56:22PM

Also works in zsh after checking the "Use Option as meta" checkbox.

I use it to track back in a long command string I need to edit. Just Option-33 and left-arrow will move 33 spaces left.

I've wanted that for a long time!

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



[ Reply to This | # ]
meta key
Authored by: sjk on Sep 07, '04 06:08:57PM

Anyone know if it's possible to enable a meta key in single-user and non-GUI shells?



[ Reply to This | # ]
meta key
Authored by: Elektron on Sep 08, '04 02:42:12PM

Command is worth trying. Otherwise, I think you have to hack the kernel's virtual console (which isn't that well written).



[ Reply to This | # ]
meta key
Authored by: sjk on Sep 08, '04 06:30:04PM

I'm long past trying modifier keys. And tweaking stty options. Seems the option and command keys aren't active at that point. And no higher-level interface like keyboard tables on Suns. Oh well.



[ Reply to This | # ]