Numeric arguments in emacs

Posted on Tue 04 April 2017 in blog

I'm starting an 'emacs trick of the day' sequence with:

  • Function name: universal-argument
  • Typical Key binding: C-u
  • How to get help: C-h f universal-argument
  • Usage: C-u

Receive a numeric argument that is given to the next called function, when no numeric argument is typed, the value defaults to 4. So today you can try:

  • C-u 9 C-n, that move cursor vertically down 9 lines
  • C-u C-k which kills 4 lines
  • C-u C-u C-k which kills 4 × 4, 16 lines
  • C-u 10 n which enters nnnnnnnnnn

You may ask, what about if I want to input 25 '6' ? C-u 256 can't work ... so you just have to separate with another C-u: C-u 25 C-u 1 gives 6666666666666666666666666.

Some functions does not have the simple 'repeating' effect of receiving a numeric parameter, for example, running C-u C-l does not recenter 4 times your screen! but the help page of recenter-top-bottom states that:

A prefix argument is handled like 'recenter': With numeric prefix ARG, move current line to window-line ARG. With plain C-u, move current line to window center. A negative argument to C-l move the current line to the line ARG from the bottom of the screen.