Hot answers tagged

13 votes
Accepted

Delete portion of Isearch string that does not match, or last char if complete match

Ah yes. Isearch reads the keys you type, looks them up in isearch-mode-map, and invokes them in the current buffer. Isearch does not, in spite of appearances, use the minibuffer. It uses the echo ...
  • 73.4k
9 votes
Accepted

how to search and replace an entire word?

You don't need to define a separate function (command) for this. And even if you did define one, it need not use query-replace-regexp. The standard command query-replace does just what you request, ...
  • 73.4k
8 votes

How can I match "snake_case" automatically when I search for "snake-case" by mistake?

I can't imagine any such automated behaviour not then causing you pain when that's not what you wanted it to do. To my mind kaushalmodi's recommendation of M-e is the best answer -- making it easy to ...
  • 46.1k
8 votes

Scrolling during isearch stops searching, losing matches

@legosia's answer is the usual one, and probably what you want. But be aware that there is an alternative Isearch behavior that lets you scroll the buffer being searched without exiting Isearch. If ...
  • 73.4k
7 votes
Accepted

When to use normal incremental search in place of the regex version?

Yes: if you want to search for a literal string, but that string contains special regex characters, it'll require extra escaping on your part. Example text to search: "some*text" C-s some*text ...
  • 32k
7 votes
Accepted

Search and replace invisible url link in org-mode

Try M-x org-toggle-link-display or the menu item Org -> Hyperlinks -> Literal Links before using isearch or query-replace. The following code does that automagically for you when you use ...
  • 609
7 votes
Accepted

Selecting (i.e., as the region) the current match in incremental search

Here's one approach: (defun isearch-exit-mark-match () "Exit isearch and mark the current match." (interactive) (isearch-exit) (push-mark isearch-other-end) (activate-mark)) (define-key ...
  • 20k
7 votes
Accepted

edit search string and begin search from current location

During Isearch M-e is bound to isearch-edit-string. It pauses Isearch and puts the current search string in the minibuffer so you can edit it. Just use C-s again to resume searching from the current ...
  • 73.4k
6 votes
Accepted

How to combine the history of isearch and query-replace?

Customize option query-replace-from-history-variable (or query-replace-to-history-variable, or both). Point to search-ring or regexp-search-ring instead of query-replace-history.
  • 73.4k
6 votes
Accepted

Quick access to the previous search terms after calling isearch-forward without switching to the minibuffer

With C-s C-s you search the previous word. Then M-p (and M-n) for history.
  • 3,149
6 votes
Accepted

Search for either of two words using isearch

C-M-s to invoke isearch-forward-regexp then type aaa\|bbb, where aaa is your first word and bbb is your second. Alternatives, just C-s to invoke isearch, then press M-r to toggle to regex.
  • 1,736
6 votes

char-fold-search match for German eszett (ß)?

By default, this is not possible (easiest way to see this is with C-h v char-fold-table RET and searching for ß — which you won't find). However, if you modify char-fold-table (the variable ...
  • 2,096
6 votes
Accepted

Extending word search selection in swiper

Try M-j, which is bound to ivy-yank-word in the ivy minibuffer key map. It's worth reading through the the ivy manual, either in Emacs or online. The relevant key bindings are discussed here: http://...
  • 20k
6 votes
Accepted

Wraparound search with `isearch-mode`

It works OK for me. Did you use C-s to repeat the search? C-s repeats Isearch, including to wrap around. You can replace the repeat-search binding: (define-key isearch-mode-map (kbd "<C-f3>") ...
  • 73.4k
5 votes

How to search an Arabic word in text without its diacritics/accents?

Here's a rough start, based on the list of combining characters in this answer (and then extended). (Marking this as community wiki — please edit and improve this!) (defconst arabic-diacritics '(#...
5 votes
Accepted

When searching, how to always ensure that a few lines after the highlighted word are visible?

(setq scroll-margin 3) Works everywhere, not just during isearch. scroll-margin. Default: 0. Number of lines of margin at the top and bottom of a window. Recenter the window whenever point gets ...
5 votes

How can I match "snake_case" automatically when I search for "snake-case" by mistake?

If you use swiper and search for snake case, it will match both snake_case and snake-case. swiper is a new isearch alternative that gives you an overview in the minibuffer as you search. In the ...
  • 13.8k
5 votes
Accepted

isearch but don't move the cursor until I ask to search

C-g, possibly repeating it, puts you back where you started and exits Isearch. Not wanting search to start until you've finished typing is not incremental search. It is plain, nonincremental search....
  • 73.4k
5 votes
Accepted

Move cursor left/right while entering isearch

You can run the command isearch-edit-string pressing M-e. See the documentation for details.
  • 1,813
5 votes

Get Emacs to jump to the start of a word after isearch

As Drew pointed out in his answer you can also end the search with another key such as M-b or M-f, which for words boundaries works good, but my solution is kind of more general: define a key to put ...
  • 239
5 votes
Accepted

Non-greedy regex not working

The problem is not about using non-greedy matching. It is about which chars you're matching. Specifically, you want to match 《 followed by any number of non-《 chars, followed by IJ》. This is a ...
  • 73.4k
4 votes
Accepted

Ringing Bell in Macro with Search

According to Emacs Wiki, you can't use isearch during a keyboard macro. http://www.emacswiki.org/emacs/KeyboardMacros#toc2
4 votes

how to search and replace an entire word?

Run query-replace-regexp with '\bi\b' as the query and 'I' as the replacement. (Update to comment) The function @lawlist linked to should work nicely if you want to replace all instances without ...
  • 6,764
4 votes
Accepted

how to customize the secondary highlighting in searches

You can change the lazy-highlight face: (custom-set-faces `(lazy-highlight ((t (:foreground "white" :background "SteelBlue"))))) But this face is used in other cases.
  • 3,149
4 votes
Accepted

How to search/isearch just comments?

Yes. Use library Isearch+, specifically file isearch-prop.el. As it says here: You can search the text of THINGS of various kind (sexps, lists, defuns, lines, pages, sentences, filenames, strings, ...
  • 73.4k
4 votes

When to use normal incremental search in place of the regex version?

@Dan provided a good answer to the question. I will add this: As @Adobe indicated in a comment, you can use M-r anytime during Isearch (literal search or regexp search) to toggle between regexp ...
  • 73.4k
4 votes
Accepted

Repeated isearch when rebound to compound key

This is because normally when you repeat an isearch command it executes the isearch-repeat-forward or isearch-repeat-backward command to save your search string (you can find this out by doing C-h k ...
  • 383
4 votes
Accepted

Can occur display just the matched part?

occur can do this with prefix argument C-u M-x occur.
  • 1,061
4 votes

Selecting (i.e., as the region) the current match in incremental search

Library Isearch+ lets you do that easily, and even toggle it on/off on the fly. Non-nil option isearchp-set-region-flag automatically sets the region (selection) around the last search target when ...
  • 73.4k

Only top scored, non community-wiki answers of a minimum length are eligible