Defining a key binding with arguments

I want to match Cf Cb as moving back and forth over a fixed number of lines in a file.

I have done this:

(global-set-key (kbd "C-f") 'next-line)
(global-set-key (kbd "C-b") 'previous-line)

but I do not know how to specify an argument before the command next-line. I think I should use digit-argument, but I can’t write the command correctly.

+5
source share
2 answers

One possible alternative would be to define a new function:

(defun my-next-line ()
  (interactive)
  (next-line 5))

(global-set-key (kbd "C-f") 'my-next-line)

Otherwise, if this is just what you can do with the keyboard, you can use

M-x name-last-kbd-macro

and save it in a .emacs file

M-x insert-kbd-macro

and emacs implement this feature for you. It will just get the name you specified when calling name-last-kbd-macro

+7
source

,

C-c l C-u 5 C-n

(global-set-key (kbd "C-c l") (kbd "C-u 5 C-n"))
+12

All Articles