In a virtual terminal I (accidentally) pressed Win+1 and got a new line consisting of
(arg: 1)
As long as I keep Win pressed, all numbers I press get appended to the number in the parentheses, e.g. Win and 1+4 yields (arg:14)
.
When I (after releasing Win) press any key, that character is printed as many times as the number reads and the (arg: ...)
expression is replaced by the standard prompt.
Does anybody know what happens here?
That’s a digit argument, a feature of the readline library built into
bash
:This feature makes it simpler to add or delete text in the currently edited command line. Let’s say you want to write
echo gggg
:echo
followed by space4g
But how often do you need to type a single letter so many times that this would save you anything? The feature is primarily designed for readline commands, see chapters 8.2.1–8.2.3 of the Reference Manual (“C” meaning Ctrl, “M” meaning Meta).
You can move back one word with Meta and B, but what if you wanted to move back multiple words at once? You can either hold Alt and press B multiple times, or use the digit argument:
There’s a typo on your command line five words back:
Press the Meta key, type
5
and press Meta and B. Et violà:You can delete a single word by pressing Meta and Backspace, but what if you wanted to delete multiple words at once?
You forgot a word on your command line:
Press the Meta key, type
4
and press Meta and Backspace.Type the missing word followed by space and press Ctrl+Y to paste what was just deleted. Et violà:
You’re right, you could’ve also moved to there as just explained without deleting anything. We’re on Linux, there are always several ways of doing the same thing.
And what’s a “negative argument”? It does the same, but in the opposite direction, so Meta
-2
Meta Backspace deletes the next two words of the command line. “But one could use Meta1
Meta D to do the same thing!” Glad you got that, welcome to your command line.Further reading: