126

Press alt + numeric in bash and you get (arg [numeric]) what is that?

(This type of question is better suited for asking a human, instead of trying to "guess" for the correct terminology to search on the documentation via internet).

dreftymac
  • 31,404
  • 26
  • 119
  • 182
  • If you have `set keymap vi` in `~/.inputrc`, then hitting `Esc + Digit` leads you to the same mode, as if preparing for a vi command repetition (but you can't use vi bindings from them on, only ugly emacs ones :-() – Ciro Santilli OurBigBook.com Mar 15 '16 at 20:38
  • My search phrases were *alt number terminal linux*, *alt + 1-9 terminal* and eventually *shell alt + 1* which brought me here. – sshow Aug 31 '18 at 09:27

7 Answers7

78

The term you want to google for is:

"readline arguments"

This will lead to, for example, this chapter from the bash reference manual:

You can pass numeric arguments to Readline commands. Sometimes the argument acts as a repeat count, other times it is the sign of the argument that is significant. If you pass a negative argument to a command which normally acts in a forward direction, that command will act in a backward direction. For example, to kill text back to the start of the line, you might type 'M-- C-k'.

The general way to pass numeric arguments to a command is to type meta digits before the command. If the first 'digit' typed is a minus sign ('-'), then the sign of the argument will be negative. Once you have typed one meta digit to get the argument started, you can type the remainder of the digits, and then the command. For example, to give the C-d command an argument of 10, you could type 'M-1 0 C-d', which will delete the next ten characters on the input line.

For that to work, you have to know where the Meta key is mapped: sometimes it's Alt, sometimes it's Esc, cool computers have a dedicated Meta key ;)

For those not familiar with the syntax, 'M-- C-k' is the equivalent of Meta_key+- Ctrl+k. "M" is shorthand for the Meta key, which, as noted, varies by system, "C" is shorthand for the Ctrl key. The "-" after a character (like "M-") is not something you type, it's a way of indicating simultaneous key presses.

Community
  • 1
  • 1
  • 3
    Is there a way to repeat numeric characters using numeric arguments? For example, say I wanted to write 128 zeros ('0'), I would think I could write Alt+128 then 0, but that gives me `(arg: 1280` (even though I let go of the Alt key). How would I repeat numbers using this mechanism? – Victor Zamanian Apr 08 '12 at 20:02
  • 1
    @Victor: interesting questions. i can't think of a way to do it with readline. you're probably better off with something like `$(perl -e 'print "0" x 128')` –  Apr 09 '12 at 00:17
  • 1
    @VictorZamanian see [another answer in this question](https://stackoverflow.com/a/11572715/1789543) – TTT Mar 25 '18 at 13:56
41

In order to repeat numeric characters - e.g. 128 zeroes, hit the following:

Meta-key + 1 2 8 Ctrl + v 0

Pavel
  • 4,912
  • 7
  • 49
  • 69
guv'
  • 1,359
  • 13
  • 8
16

Try this. Type Alt 4, then type T, then hit Enter.

Edited to use the snazzier HTML.

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
12

I know this has already an accepted answer however I did find some useful examples that also demonstrate additional uses aside from simple repeating of characters. The digit arguments can apply to all sorts of things. For example the sequence "Alt+3, Escape, Backspace" will delete backwards 3 words.

stsquad
  • 5,712
  • 3
  • 36
  • 54
12

It repeats the next command given that many times, same as in Emacs. E.g. M-1-0 C-p moves back 10 history items. M-4 C-h backspaces four characters, M-3 M-t moves the previous word forward three times, and so on. Here I use M- meaning "meta" for the Alt key, as is the custom in Bash.

viam0Zah
  • 25,949
  • 8
  • 77
  • 100
Nietzche-jou
  • 14,415
  • 4
  • 34
  • 45
5

I don't know but when you do alt + numeric and then you press a character, you'll get num caracters: (arg: 123) + a -> 123 times "a"

JuanDeLosMuertos
  • 4,532
  • 15
  • 55
  • 87
2

bash manual section - basically a way of repeating readline commands, or reversing them.

Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137