Emacs: Universal Argument (prefix arg)
What is Universal Argument
universal-argument
【Ctrl+u】
allows you to give argument to commands, interactively.
What the command do with argument depends on the command. It may repeat the command, or have different behavior (e.g. copy file name without dir path, or copy full path.) .
Example of universal-argument
- Type Ctrl+u 60 - to insert hyphen, 60 times.
- In dired,
dired-copy-filename-as-kill
【w】 copies the file name, but type Ctrl+u 0 first, then w, the copied name is file full path.
- with Ctrl+u,
shell
starts a new buffer
- with Ctrl+u,
shell-command-on-region
replace region with output.
digit-argument, negative-argument
These are equivalent of universal-argument.
digit-argument
is equivalent to callinguniversal-argument
【Ctrl+u】 then type a number.negative-argument
is equivalent to callinguniversal-argument
【Ctrl+u】 then type a negative number.
Keyboard shortcuts for digit-argument
- The keys Ctrl+1 to Ctrl+9 and Meta+1 to Meta+9 are bound to
digit-argument
. - The key Ctrl+- and Meta+- calls
negative-argument
.