Hot answers tagged

31 votes
Accepted

Counsel M-x always shows "^"

ivy-initial-inputs-alist is a variable that controls the default minibuffer contents when using ivy (which is used by counsel). The default "^" string means that if you type something immediately ...
mkcms's user avatar
  • 1,340
26 votes
Accepted

Only show lines containing phrase/regex

...see all the lines from the current buffer... With built-in commands and no external packages or dependencies in a new buffer, use: M-x occur the same buffer, use: M-x keep-lines
Emacs User's user avatar
  • 5,503
17 votes

How do I find text across many open buffers?

swiper-all from the swiper package provides a tool for doing this. It's even incremental, so it updates as you type.
Wilfred Hughes's user avatar
16 votes
Accepted

Search through the values of all variables in Emacs

Does apropos-value do what you're looking for? (apropos-value PATTERN &optional DO-ALL) Show all symbols whose value’s printed representation matches PATTERN. PATTERN can be a word, a list of ...
genehack's user avatar
  • 471
10 votes
Accepted

Difference between `evil-search-forward` and `evil-ex-search-forward`

evil has two search implementations, one is its own, the other one is a wrapper around emacs isearch. evil-search-forward wraps isearch-forward, evil-ex-search-forward invokes the internal search. ...
Yuri Steinschreiber's user avatar
10 votes
Accepted

Is there a more efficient alternative to search-forward when searching for a single character?

I have run the following benchmarks on GNU Emacs 27.0.50 (build 14, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2018-02-21 without customisations, i.e. by starting Emacs with the -Q flag. ...
Basil's user avatar
  • 11.9k
10 votes
Accepted

Swiper get last search term

When you invoke swiper press M-p to search for previously searched thing. M-n will let you search for the word under cursor. C-s will search for the next occurence. UPD, thx @Basil After you ...
Maxim Kim's user avatar
  • 1,391
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, ...
Drew's user avatar
  • 74.6k
9 votes
Accepted

How to select text found by `re-search-forward`?

One way to do it: (defun my-search-forward (str) (interactive "smy-search-forward: ") (when (re-search-forward str nil t) (setf (point) (match-beginning 0) (mark) (match-end 0))))
PythonNut's user avatar
  • 10.2k
9 votes
Accepted

Gracefully Exiting a While Loop

re-search-forward has an option for not causing an error: (re-search-forward REGEXP &optional BOUND NOERROR COUNT) You should call (re-search-forward "..." nil t) and your while will receive a ...
Juancho's user avatar
  • 5,225
9 votes
Accepted

How to check if a string exists in the current buffer?

I think the easiest approach would be (save-excursion (goto-char (point-min)) (search-forward string nil t)) This will return non-nil if the given string is in the current buffer.
YoungFrog's user avatar
  • 3,466
9 votes
Accepted

Does "Occur-at-point" already exist?

There are a number of Emacs commands for which M-n at the input prompt (next-history-element) will insert a reasonable default if there is no next history element available. For occur that happens to ...
glucas's user avatar
  • 20.1k
8 votes

Getting number of occurrences, during incremental search (C-s / isearch-forward)

As of emacs 27.1, this is now built-in to isearch. To turn on: (setq isearch-lazy-count t) To compare with anzu, the count is shows in the minibuffer prompt, rather than the modeline. See the ...
bnzmnzhnz's user avatar
7 votes

How to center the current line vertically during Isearch

The simplest way to do this is: (defadvice isearch-update (before my-isearch-reposite activate) (sit-for 0) (recenter 1)) A better but more complicated: (defadvice isearch-update (before my-...
link0ff's user avatar
  • 1,061
7 votes
Accepted

How to center the current line vertically during Isearch

For Isearch, you can set option isearch-allow-scroll to non-nil. That lets you scroll the buffer you are searching, without exiting Isearch. And note that "scrolling" here includes C-l, which ...
Drew's user avatar
  • 74.6k
7 votes

What is the easiest way to search all useful files inside a single project?

If your project uses Git, you only need counsel https://github.com/abo-abo/swiper counsel-git to find file counsel-git-grep to grep The only dependency is git Text grepping is faster than the ...
chen bin's user avatar
  • 4,771
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 ...
Dan's user avatar
  • 32.3k
7 votes

How to search in multiple files with Emacs without grep?

You can use Windows' builtin findstr command with M-x rgrep: (when (eq system-type 'windows-nt) (with-eval-after-load 'grep ;; findstr can handle the basic find|grep use case (grep-apply-...
npostavs's user avatar
  • 8,983
7 votes

How to search in multiple files with Emacs without grep?

you can try the xah-find package. https://github.com/xahlee/xah-find it is pure elisp, and designed just for emacs without external grep tools.
Xah Lee's user avatar
  • 1,746
7 votes

How to search in multiple files with Emacs without grep?

The Elisp package elgrep is a swiss army knife for searching files. It is available on melpa. There are no dependencies on external tools as long as you do not search the contents of pdf documents. ...
Tobias's user avatar
  • 32.1k
7 votes
Accepted

how do I do case sensitive searches using evil/spacemacs?

Short and narrow answer You need to set the variable case-fold-search to nil in order to have case sensitive search. So: put this somewhere in your init file: (setq case-fold-search nil) See the ...
Dan's user avatar
  • 32.3k
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 ...
glucas's user avatar
  • 20.1k
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 ...
Drew's user avatar
  • 74.6k
7 votes
Accepted

How to search by tags in org-mode

org-tags-view shows matches in all agenda files: you have to add this file to your agenda files (at least temporarily). You can do that with C-c[: that adds it to the front of the list of agenda files ...
NickD's user avatar
  • 25.9k
6 votes
Accepted

How to get back to minibuffer during an interactive search?

You can hit M-e to edit the current search term. This runs the command isearch-edit-string. You can then type C-s to resume the search. To get a list of all key bindings available during isearch, ...
nanny's user avatar
  • 5,644
6 votes
Accepted

How do I search the whole word in swoop?

You can use any regexps supported by Emacs, which provides \b as a match for the boundary of a word. So swooping for \bin\b will match in but not input, begin or being. The full list of Emacs-...
Tyler's user avatar
  • 21.4k
6 votes
Accepted

in Emacs regex, how to search for uppercase letters only?

You can temporarily bind case-fold-search using let: (let ((case-fold-search nil)) (looking-at "[\n\t ]*[A-Z]")) Also, I changed your regexp for matching whitespace and newlines -- a ] was missing ...
Lindydancer's user avatar
  • 6,065
6 votes

Is it possible to insert word at point in swiper?

You can insert symbol at point with M-n - the same key as the history forward, which is one of the recommended Emacs workflows for inserting thing at point. Additionally, M-j will extend the ...
abo-abo's user avatar
  • 13.9k
6 votes
Accepted

History of search terms for evil mode?

You will find things more Vim like with the Evil search module rather than isearch search module with Evil : (evil-select-search-module 'evil-search-module 'evil-search)
Jeeves's user avatar
  • 601

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