Hot answers tagged

32

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 monitor and ignore all others. It can run grep, ack (requires ack-and-a-half.el) and ag (ag.el) on files within the defined project (either based on the ....


31

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 it's tedious. multi-occur-in-matching-buffers lets you enter a regexp to match file names (it only searches in buffers that are visiting files); enter . as the ...


24

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 configure this as the default behavior customize option search-whitespace-regexp to nil. (M-x customize-option search-whitespace-regexp.) See the GNU Emacs manual,...


19

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 occurrence. Any command other than typing text, backspace and a few others exits search mode; in particular, press RET to continue editing where the occurrence was ...


16

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 github and via MELPA. It has your required functionality of being able to drop your point at the position of the match (which can be a regexp). But you can also ...


15

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.


14

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 after this string only completion candidates that begin with what you typed are shown. You can remove this default string in counsel-M-x command with: (setcdr (...


13

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 searches to NOT use the ignore list from the version-control ignore lists by using the -U switch. If there are files in your source repo you don't want to search, ...


13

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 with the current search expression. At the top of the *Occur* buffer is the number of matching lines. The command how-many displays the number of occurrences of a ...


12

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 buffers. If you use Icicles then you can use icicle-search (or icicle-occur, or any number of other icicle-search specializations) to search across multiple ...


12

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.


11

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-ag.


11

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 in your search string will match any sequence matched by the regular expression defined by the search-whitespace-regexp variable. To match words across line ...


11

...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


11

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 words (separated by spaces), or a regexp (using some regexp special characters). If it is a word, search for matches for that word as a substring. If it is a ...


10

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 selection." (interactive "sEnter tag name: ") (let (p1 p2 inputText) (if (use-region-p) (progn (setq p1 (region-beginning) ) ...


10

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 MELPA with helm-mode on, using either i (info-index) or I (info-virtual-index) pops up a helm window with the index terms. You can then use typical helm ...


10

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 and then select all buffers. Instead of using M-a to mark all buffers, you can optionally select the buffers of interest one at a time. Navigate up and down the ...


10

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

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. Is there a more efficient alternative to search-forward when searching for a single character? [...] Does something like search-forward-char exist ...


9

swiper-all from the swiper package provides a tool for doing this. It's even incremental, so it updates as you type.


9

You can use query-replace-regexp (C-M-%). Replace ^\(.*\)$ with <li>\1</li>.


9

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

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 nil value when no match found. Edit: As Jordon notes in the comments, there is a more general way of ignoring errors, which is the ignore-errors macro: (while ...


8

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 RET or C-h r i search TAB ing RET. If someone is really at this basic a level with Emacs, then the real question is how to look something up in the manual, ...


8

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 (&optional regexp-p) (interactive "P") (let* ((beg (line-beginning-position)) (end (line-end-position)) (isearch-message-prefix-add "[Line]") ...


8

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, if you provide it with a prefix argument. So just use C-u M-% to query-replace words. C-h f query-replace tells you this (note the part in bold): query-...


8

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.


8

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. Which one is used is governed by the variable evil-search-module, the default is isearch. In this mode, evil's search behaves exactly like emacs' (because it is.) ...


7

The most direct way of doing this would be to Mark the region of text lines to become a list Press M-% (query-replace) Type C-q C-j RET </li> C-q C-j <li> RET (C-q C-j inserts a quoted newline character) Press ! to replace all occurrences


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