Emacs: Search Current Word 🚀
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 about 8 keys. In vim, it's just a single key press *.
2014-03-11 addendum:
Emacs 24.4 (Released 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. [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 “xx”, it'll will not find occurrences of “xx2”.
Command to Search Current Word
Here's a command to isearch the word under cursor.
(defun xah-search-current-word () "Call `isearch' on current word or selection. “word” here is A to Z, a to z, and hyphen [-] and lowline [_], independent of syntax table. URL `http://xahlee.info/emacs/emacs/modernization_isearch.html' Version: 2015-04-09" (interactive) (let (xp1 xp2) (if (region-active-p) (setq xp1 (region-beginning) xp2 (region-end)) (save-excursion (skip-chars-backward "-_A-Za-z0-9") (setq xp1 (point)) (right-char) (skip-chars-forward "-_A-Za-z0-9") (setq xp2 (point)))) (setq mark-active nil) (when (< xp1 (point)) (goto-char xp1)) (isearch-mode t) (isearch-yank-string (buffer-substring-no-properties xp1 xp2))))
You need to give it a easy key. Such as F8. 〔see Emacs Keys: Define Key〕
Also, you should set your isearch repeat to arrow keys. Emacs Init: isearch by Arrow Keys.
Emacs Find Replace
- Emacs: Search Text in Current File
- Emacs: Search Current Word 🚀
- Emacs Init: isearch Whitespace Regex
- Emacs Init: isearch by Arrow Keys
- Emacs: Highlight Word, Line
- Emacs: List Matching Lines
- Emacs: Search Text in Directory
- Emacs: Find Replace in Current File
- Emacs: Interactive Find Replace Text in Directory
- Emacs: Xah Find Replace (xah-find.el) 📦
- Emacs: Regular Expression
Emacs Modernization
- Emacs Modernization: Simple Changes Emacs Should Adopt
- Why Emacs Keys are Painful
- Emacs: Problems of the Scratch Buffer
- Emacs Modernization: Meta Key Notation
- Emacs Menu Usability Problem
- Emacs Mode Line Problem
- Emacs cua-mode Problems
- Emacs: Inconsistency of Search Features
- Problems of grep in Emacs
- Emacs: Usability Problems of Mode Documentation
- Problems of Emacs Manual
- Emacs Manual Sucks by Examples
- Emacs: kill-buffer Induces Buffer Accumulation
- Emacs Spell Checker Problems
- Emacs: Form Feed ^L Problem
- Emacs: Single Key to Delete Whole Line
- Emacs HTML Mode Sucks
- Emacs Does Not Support Viewing Images Files In Windows
- Emacs Should Adopt HTML as Texinfo Replacement
- Emacs Should Support HTML Mail
- Problems of Emacs's “man” Command
- Emacs Lisp Mode Syntax Coloring Problem
- Emacs AutoHotkey Mode Problems
- Elisp: Syntax Table Sucks
- Emacs: Make elisp-index-search use Current Symbol
- Emacs GNU Texinfo Problems; Invalid HTML
- A Record of Frustration in IT Industry; 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)
- Thoughts on Common Lisp Scheme Lisp Based Emacs
- Text Editors Popularity and Market Research
- Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
- Emacs: Usability Problems of Letter-Case Changing Commands
- Emacs Select Word Command Problem
- Emacs: Search Current Word 🚀
- Emacs fill-paragraph Problem