Emacs Flaw: isearch Current Word

By Xah Lee. Date: . Last updated: .

Problem with Emacs's isearch

Emacs's “isearch” command have inconvenience problem of searching the current word.

Suppose you have this line:

aa-bb-▮cc xx yy

and your cursor is on the second hyphen. You want to search the next occurrence of the word “aa-bb-cc”. You have to press

Alt+b Alt+b Ctrl+s Ctrl+w Ctrl+w Ctrl+w Ctrl+s

That's 14 keys. vim, it's just a single key press *.

Problem of isearch-forward-symbol-at-point

Emacs 24.4 (date 2014-10) has the new command isearch-forward-symbol-at-point that improved the situation but still pretty bad.

Now to search current word under cursor, you need to press

Alt+s . Alt+s _ Ctrl+s

Besides the too-many-keys problem, this command has more problems:

  1. isearch-forward-symbol-at-point is on “symbols” only. What chars are part of “symbol” is unpredictable, mode-dependent.
  2. The search is with boundary check. That is, if current symbol is “xx”, it'll will not find occurrences of “xx2”.

Problem Example

Try this. Create a file with this content:

xyz
~/xyz/

put your cursor at the beginning of the xyz.

Now call isearch-forward-symbol-at-pointAlt+s .】, then press Ctrl+s. A total of 5 keys.

did it land on the “~/xyz/”?

why not? because it searches the “symbol” with added boundary check. (see its doc string) So this means, it's nice if you are in a programing language source code and are searching function/variable names and don't want to jump to another name that happens to contain it as substring. But, in a config file or general text soup, you get stung.

but you can toggle it so it just search string without caring about boundary. Press Alt+s _ while in isearch.

that is 3 keys.

so, it's Alt+s . Alt+s _ Ctrl+s. One heck of a somersault.

Solution

Emacs Find Replace