Emacs: Universal Argument (prefix arg)
Emacs has a mechanism for a command to have variant behavior if user calls universal-argument
【Ctrl+u】
first, before calling the command.
The purpose of
universal-argument
is:
- A convenient way to let user pass numerical argument to a command. (What the command do with number argument depends on the command. Usually repeating the command.)
- To have a alternate behavior of a command. (e.g. copy file name without dir path, or copy full path.)
Keyboard shortcuts:
- The keys Ctrl+1 to Ctrl+9 and Meta+1 to Meta+9 are bound to
digit-argument
. It is equivalent to callinguniversal-argument
【Ctrl+u】 then type a single digit number. - The key Ctrl+- and Meta+- calls
negative-argument
. It is equivalent to callinguniversal-argument
【Ctrl+u】 then type a negative number.
Examples
Type Ctrl+u 60 - to insert hyphen, 60 times.
In Emacs: File Manager, dired, type w
(dired-copy-filename-as-kill
)
copies the file name, but type Ctrl+u 0 first, then w, the copied name is file full path.