Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind 'search' and 'search-repeat' to C-f in Emacs?

Tags:

emacs

How can I to remap incremental search (C-s) to C-f in Emacs?

I try to do (global-set-key (kbd "C-f") 'isearch-forward) but the second C-f does not repeat the search and I need to use C-s.

I then tried (global-set-key (kbd "C-f") 'isearch-repeat-forward) but the first C-f didn't start the search.

And I even tried (global-set-key (kbd "C-f C-f") 'isearch-repeat-forward), but this causes an error.

I want to use C-f for search and search-repeat commands, how can I do this?

Thanks.

like image 492
Fernando Almeida Avatar asked Sep 14 '11 06:09

Fernando Almeida


2 Answers

(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)

like image 168
Ross Patterson Avatar answered Oct 09 '22 09:10

Ross Patterson


isearch-repeat-forward is defined in the isearch-mode-map

To resolve your problem do the following :

(global-set-key (kbd "C-f") 'isearch-forward)

(add-hook 'isearch-mode-hook
 (lambda ()
 (define-key isearch-mode-map (kbd "C-f") 'isearch-repeat-forward)
 )
)

EDIT: actually, you don't need to add a hook. The accepted answer by Ross Patterson is correct.

like image 21
Oleg Pavliv Avatar answered Oct 09 '22 09:10

Oleg Pavliv