Skip to main content
9 votes
Accepted

Insert multiple minus ('-') characters using the universal argument (C-u)

For example, C-u C-u C-q -. You can C-h k C-q for more details.
shynur's user avatar
  • 5,890
7 votes
Accepted

What is the difference between `C-u C-c C-l` and `C-c C-l`?

Disclaimer I couldn't find a resource providing a good and understandable explanation about prefix arguments for new Emacs users. So I am a newbie and my explanation may not be the best. Prefix ...
buhtz's user avatar
  • 749
6 votes
Accepted

How to rebind "special meaning" of C-u to a different key?

Add at least one additional definition: (global-set-key (kbd "C-i") 'universal-argument) (define-key universal-argument-map (kbd "C-i") 'universal-argument-more) See additional universal-... ...
lawlist's user avatar
  • 19.5k
6 votes
Accepted

How to specify prefix argument in key binding

C-u invokes the function universal-argument, and you want to ensure that eval-last-sexp is called as if you invoked it interactively, which is done with call-interactively. You can simulate universal-...
rpluim's user avatar
  • 5,585
5 votes
Accepted

Assign a function with universal argument to a key (org-timer-start)

The part you need to look at is the interactive declaration which in this case is (interactive "P"). This means that C-u is passing the argument (4) to org-timer-start. So you need to assign ...
Aidan Schofield's user avatar
5 votes

Use cases for M-0 & C-0?

There is a common convention that a numeric prefix argument means “do it this many times”. If a command follows this convention, a prefix argument of 0 is useless. However, not all commands follow ...
Gilles 'SO- stop being evil''s user avatar
5 votes
Accepted

How to bind 'C-u M-x shell' to 'C-c s'?

You need to set universal-prefix-argument and call shell interactively: (global-set-key (kbd "C-c s") (lambda () (interactive) (let ((current-prefix-arg '(4))) (call-interactively #'...
muffinmad's user avatar
  • 2,340
4 votes
Accepted

What's the difference between C-u C-u C-u <Command> and C-u 64 <Command>?

There is a subtle distinction between C-u C-u C-u Tab and C-u 64 Tab. When you use only the C-u key, without using digits (i.e., 64), what actually gets passed to the org-cycle function (which is what ...
Tyler's user avatar
  • 22.8k
4 votes
Accepted

What function are associated with these expression evaluation commands in buffers?

I think the only relevant key-binding to search is: C-x C-e which for me is bound to eval-last-sexp. C-0 and C-u 0 are prefix args that are passed to the function that C-x C-e is bound to; they don't ...
John Kitchin's user avatar
  • 12.1k
4 votes
Accepted

Using current prefix argument value

You should consider that interactive functions can also get called non-interactively. So this is where the 'interactive' form comes in; the arguments passed via interactive are only passed when ...
dalanicolai's user avatar
  • 7,985
4 votes

Insert multiple minus ('-') characters using the universal argument (C-u)

To type a minus sign with a numeric prefix argument, you can enter the number by typing the digits: C-u 6 4 - or ESC 6 4 - or M-6 M-4 - or C-6 C-4 - (or a few other combinations). This method doesn't ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

Can there be two prefix arguments?

There are no multiple prefix arguments. The interactive specification (interactive "*P\nP") means that the one-and-only raw prefix argument is used twice for the command arguments. In the ...
Tobias's user avatar
  • 33.7k
3 votes

What is the difference between `C-u C-c C-l` and `C-c C-l`?

Meta-answer: since the universal prefix argument (C-u) given once or more modifies a command's behavior, a properly-written command will thoroughly document each prefix argument. org-insert-link is ...
Phil Hudson's user avatar
  • 1,798
3 votes
Accepted

Are the Control & Meta "digit argument" bindings duplicates?

Yes, they are duplicates. If you want to use one of them for your own purposes, I would recommend to keep the meta ones and rebind the control ones. One reason to keep the meta ones is that if you run ...
Gilles 'SO- stop being evil''s user avatar
3 votes

Are the Control & Meta "digit argument" bindings duplicates?

They are duplicates, indeed. The reason they exist is to make it more ergonomic to type digit arguments regardless if the next command uses Meta or Control. For example, typing C-5 M-f is very ...
nohans's user avatar
  • 70
3 votes
Accepted

How can I pass an expression to a prefix argument?

There's no convenient interface for that. For some simple operations, you can make use of two facts: Using C-u with no number gives you powers of 4. C-u C-n moves 4 lines down, C-u c-u C-n moves 16 ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

Given a keyboard command, how do you find the interactive function?

describe-key is bound to C-h k. If you want to know the function bound to C-u C-c ., you should consider that C-u is a prefix to C-c . and use just C-h k C-c .. In this case, C-h k C-c . tells you ...
adl's user avatar
  • 646
3 votes

Use cases for M-0 & C-0?

@gilles and @npostavs have given use cases. To summarize what they said: When you're already using C- or M- for part of a key sequence, it can be easier to specify a zero prefix arg using C-0 or M-0 ...
Drew's user avatar
  • 79.1k
2 votes

Finding possible prefix arguments

A list of all commands "that take prefix arguments" means a list of all commands. If you instead mean a list of only those commands whose doc mentions prefix-argument behavior then you need to search ...
Drew's user avatar
  • 79.1k
2 votes

Finding possible prefix arguments

Here is one way to get the functions that mention prefix in the doc string. This saves the output to a file (with-temp-file "prefix-cmds.org" (loop for cmd-name in smex-ido-cache do (let* ((...
John Kitchin's user avatar
  • 12.1k
2 votes

Swap default behavior of command with C-u behavior

Another method based on the fact that an interactive-form property in the function's plist overrides the form specified in code: (ref) (put 'org-insert-subheading 'interactive-form '(...
olejorgenb's user avatar
2 votes

Use cases for M-0 & C-0?

I cannot think any use case... It just makes entering numeric prefix arguments a little easier. For example, with numeric argument of 0, C-k (kill-line) will delete from point to the beginning of ...
npostavs's user avatar
  • 9,253
2 votes
Accepted

How to write a command which uses the prefix argument AND some strings

Your string example shows that you already know how to separate multiple interactive arguments, by putting a newline between each one in the interactive spec. So rather than: (interactive "PstEins: \...
phils's user avatar
  • 53.1k
2 votes
Accepted

how to implement a numeric prefix argument in emacs

Pass the number of times as the numeric prefix arg. See the Elisp manual, node Prefix Command Arguments and node Using `interactive'. (defun my/elfeed-extra-info (&optional numtimes) ; <=== ...
Drew's user avatar
  • 79.1k
2 votes
Accepted

Find out about arguments passed to functions

set-mark-command (as the name suggests) is meant to be used as a command and not called as a function. For that reason, the docstring talks about the interactive uses rather than the case where you ...
Stefan's user avatar
  • 26.7k
2 votes
Accepted

How to define key-combinations involving multiple `C-u`s

The doc string of org-latex-preview says (org-latex-preview &optional ARG) Toggle preview of the LaTeX fragment at point. If the cursor is on a LaTeX fragment, create the image and overlay it ...
NickD's user avatar
  • 33.6k
2 votes

Can there be two prefix arguments?

@Tobias has answered the question, but just in case you've found this Q&A because you want to be able to supply multiple different prefix arguments to a command, take a look at the transient ...
phils's user avatar
  • 53.1k
1 vote
Accepted

How can I get the name of the file on the current Dired line?

Not sure what you're asking, but I think you're asking how to have dired-get-marked-files pick up only the file named on the current line, instead of the files that are marked. If so, the answer is to ...
Drew's user avatar
  • 79.1k
1 vote

Using a number in register as prefix argument

This should do the trick. (defun reg-as-pref-arg (register) "Use numeric register as prefix arg for next command You are prompted for the register, showing preview of registers." (...
Drew's user avatar
  • 79.1k
1 vote
Accepted

"C-3" vs "C-u 3-" in spacemacs

Disclaimer: My answer pertains to vanilla Emacs features and default keybindings. The concepts should be the same in Spacemacs, but the default bindings may differ. If I hit the control key and the ...
Basil's user avatar
  • 12.6k

Only top scored, non community-wiki answers of a minimum length are eligible