12
votes

I'm using Emacs v24.3 on Windows 7. I'm trying to learn how to remap key bindings.

I've created an .emacs file in my home directory and it contains one line:

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

I start up Emacs with runemacs.exe. I find a non-existant file, type some words (click at the start of the text) and type C-F to find. The I-search: prompt displays and I can incrementally search for text. So far so go.

The problem is, if the behavior is suppose be the same as the default isearch-forward keystroke, C-s, it isn't. When I type C-f a second time to search for the next occurance of the string, the only thing that happens is the I-search prompt appears in the minibuffer.

I'm not able to search for the next occurance of the string. Additionally, the Del key is suppose to repeate the search in the reverse direction. That does not happen for me when I search using C-f (though it does when I search using C-s.).

So this single key mapping seems to break two things. Am I mapping wrong? Or are these bugs? If I'm mapping wrong, how do I map C-f to the isearch-forward command?

2

2 Answers

16
votes

Along with your one line, add:

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

The issue is that isearch has its own bindings that are active once you start an incremental search. Adding the expression above remaps the binding for isearch-repeat-forward.

If you're curious about these bindings, you can enter C-h b while doing an incremental search to examine the full keymap.

0
votes

No, I don't think the tutorial says that. I think you are referring to section SEARCHING and this text:

>> Type C-s again, to search for the next occurrence of "cursor".
>> Now type `<DEL>` four times and see how the cursor moves.

If you are in the middle of an incremental search and type <DEL>, the
search "retreats" to an earlier location.  If you type <DEL> just
after you had typed C-s to advance to the next occurrence of a search
string, the <DEL> moves the cursor back to an earlier occurrence.  If
there are no earlier occurrences, the `<DEL>` erases the last character
in the search string.  For instance, suppose you have typed "c", to
search for the first occurrence of "c".  Now if you type "u", the
cursor will move to the first occurrence of "cu".  Now type <DEL>.
This erases the "u" from the search string, and the cursor moves back
to the first occurrence of "c".

A <DEL> does not search backward. It removes a character from the search string, and search moves to the previous hit (only) for the resulting string. But the first <DEL> after C-s does not alter the search string. It just moves to the previous hit (only).

The tutorial text is not incorrect, though it might be a bit difficult to read. If you have a suggestion for improving it or just want to let Emacs Dev know that you find it unclear, please use M-x report-emacs-bug.