44
votes
How do I find text across many open buffers?
Sticking to built-in Emacs commands, you can use multi-occur or multi-occur-in-matching-buffers (M-x multi-occur- TAB RET). multi-occur gives you fine control by prompting for each buffer to use, but ...
37
votes
Accepted
What is the easiest way to search all useful files inside a single project?
Project based searching within Emacs can be done using projectile.
It allows for per-project configuration of ignore files (in a <projectroot>\.projectile file), or specify subdirectories to ...
31
votes
Accepted
Match two spaces with incremental search
Use M-s SPC during Isearch to toggle matching whitespace literally. When matching literally, each SPC char you type is matched individually. (This used to be the default Emacs behavior, BTW.)
To ...
29
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 ...
24
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
22
votes
Accepted
Search for text and navigate between the occurrences
The manual is your friend!
The basic search capability is incremental search. Press C-s and enter the string to search (C-r to search backwards). Press C-s/C-r again to go to the next/previous ...
17
votes
Accepted
Helm: search within buffer feature?
You can use helm-occur as a tool that comes with the basic helm module for this.
But to me, one of the best helm based tools for buffer searching is Shingo Fukuyama's helm-swoop. You can get it from ...
15
votes
Accepted
Getting number of occurrences, during incremental search (C-s / isearch-forward)
The anzu package does that.
anzu.el provides a minor mode which displays current match and total matches information in the mode-line in various search modes.
15
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 ...
14
votes
What is the easiest way to search all useful files inside a single project?
The project-wide search of only relevant files can be done using ag aka the_silver_searcher.
Why ag?
It ignores file patterns from your .gitignore, .hgignore, svn:ignore. You can choose for your ...
14
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.
14
votes
How to search the Emacs Lisp Reference Manual?
You can use elisp-index-search. I use it daily.
I use it mostly when I already know a function name and want to see it in emacs lisp manual.
14
votes
Getting number of occurrences, during incremental search (C-s / isearch-forward)
Here are some possibilities that aren't very slick, that have the advantage of working with a stock Emacs.
If you press M-s o (isearch-occur) during an incremental search, an Occur buffer pops up ...
13
votes
Accepted
How to search the Emacs Lisp Reference Manual?
EDIT: I just found the wonderful M-x info-apropos which searches full text over all info documents and returns the relevant nodes. Seems this gem is relatively unknown.
If you use helm package from ...
13
votes
Search for string ignoring new lines
Take a look at the variables isearch-lax-whitespace, isearch-regexp-lax-whitespace, and search-whitespace-regexp.
If the first two variables are set to something non-nil (e.g. t) any space character ...
12
votes
How do I find text across many open buffers?
In addition to what others have mentioned - here are two other resources for this.
M-x multi-isearch-buffers or M-x multi-isearch-buffers-regexp (vanilla Emacs) - Incremental search across multiple ...
12
votes
How do I find text across many open buffers?
This can be done with helm via the command helm-multi-occur. You can install helm from melpa and then call the command as follows:
M-x helm-multi-occur RET M-a RET
This will open helm-multi-occur ...
11
votes
helm-ag (or similar) find in javascript files only
If you use helm-ag command, you can specify option like -G\.js$ search_pattern, or if you use helm-do-ag, you can use C-u prefix for specifying extension.
This is screencast.
Thanks for using helm-...
10
votes
Accepted
Recursively find all files from a folder containing a regexp in the filename, using helm
On systems that provide GNU find utility, you can use helm-find (by default bound to C-x c /) to get the desired behavior. Starting helm-find with a prefix argument C-u C-x c / prompts for the ...
10
votes
Search for text and navigate between the occurrences
Instead of just providing a link to the manual section section about searching, the real "the manual is your friend" answer is to tell you how to look this up in the manual yourself: C-h r i searching ...
10
votes
How to convert a series of lines into a working HTML list?
Alternatively to query replace you can go with multiple-cursors:
Also consider using something like this:
(defun wrap-html-tag (tagName)
"Add a tag to beginning and ending of current word or text ...
10
votes
How to search *just* the current line
Select the current line ( C-a C-SPC C-e )
Narrow region ( C-x n n )
Perform search using any method
Go back to the original buffer by widening ( C-x n w )
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.
...
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, ...
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))))
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 ...
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 ...
8
votes
How to convert a series of lines into a working HTML list?
You can use query-replace-regexp (C-M-%). Replace ^\(.*\)$ with <li>\1</li>.
8
votes
Accepted
How to search *just* the current line
Isearch is quite flexible and if you become tired of constantly
narrowing the buffer (as was suggested), you may want to have a
dedicated command for this, e.g.
(defun isearch-line-forward (&...
8
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.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
search × 278regular-expressions × 43
replace × 39
helm × 24
isearch × 23
org-mode × 20
spacemacs × 10
evil × 10
dired × 9
region × 9
grep × 8
latex × 6
whitespace × 6
query-replace × 6
highlighting × 5
ivy × 5
motion × 5
occur × 5
words × 5
swiper × 5
case-folding × 5
key-bindings × 4
org-agenda × 4
buffers × 4
files × 4