Emacs: isearch Current Word
Here's a command to isearch the word under cursor.
(defun xah-search-current-word () "Call `isearch' on current word or text selection. “word” here is A to Z, a to z, and hyphen 「-」 and underline 「_」, independent of syntax table. URL `http://xahlee.info/emacs/emacs/modernization_isearch.html' Version 2015-04-09" (interactive) (let ( $p1 $p2 ) (if (use-region-p) (progn (setq $p1 (region-beginning)) (setq $p2 (region-end))) (save-excursion (skip-chars-backward "-_A-Za-z0-9") (setq $p1 (point)) (right-char) (skip-chars-forward "-_A-Za-z0-9") (setq $p2 (point)))) (setq mark-active nil) (when (< $p1 (point)) (goto-char $p1)) (isearch-mode t) (isearch-yank-string (buffer-substring-no-properties $p1 $p2))))
You need to give it a easy key. Such as F8. [see Emacs: How to Define Keys]
Also, you should set your isearch repeat to arrow keys. Emacs: isearch by Arrow Keys.
Problem with Emacs's isearch
Emacs's “isearch” has some problems. Suppose you have this line:
… aa-bb-▮cc xx yy …
and your cursor is on the second dash. 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 about 8 keys. In vim, it's just a single key press *.
addendum: Emacs 24.4 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. [see Emacs: Search Text in Current File] Besides the too-many-keys problem, this command has more problems:
isearch-forward-symbol-at-point
is on “symbols” only. What chars are part of “symbol” is unpredictable, mode-dependent.- The search is with boundary check. That is, if current symbol is “xyz”, it'll will not find occurrences of “xyz2”.
Emacs Find Replace
Emacs Modernization
- Simple Changes Emacs Should Adopt
- Why Emacs Keys are Painful
- Ban Scratch Buffer
- M-x vs Alt+x Notation
- Menu Idiocy
- Mode Line Problem
- cua-mode Problem
- Inconsistency of Search
- grep in emacs Pain
- Problems of describe-mode
- Problems of Emacs Manual
- Emacs Manual Sucks by Examples
- kill-buffer Problem
- Emacs Spell Checker Pain
- Form Feed ^L
- Single Key Delete Whole Line
- Emacs HTML Mode Sucks
- Emacs No View Image on Windows
- HTML should replace Texinfo
- Support HTML Mail
- Problems of “man”
- Emacs Lisp Mode Syntax Coloring Problem
- Emacs AHK Mode Problems
- Ban Syntax Table
- Make elisp-index-search use Current Symbol
- Texinfo Invalid HTML
- Disappearing FSF URLs, 2006
- Emacs Manual Node Persistency Issues
- Emacs: dired-do-query-replace-regex Replace ALL (fixed)
- Problems of Emacs Supporting Obsolete Systems
- Elisp: Function to Copy/Delete a Dir Recursively (fixed)
- CommonLisp/SchemeLisp Emacs
- Text Editors Popularity
- Cursor Movement Behavior Survey
- Letter-Case Commands Problem
- Select Line/Block/Quote, Extend
- isearch Current Word
- Reformat Line Wrap