2022 Developer Survey is open! Take survey.

Hot answers tagged

20 votes

How to recursively search / grep file contents in a directory / subdirectories in Emacs?

Well, since the original question doesn't mention rgrep, I'll go ahead and point it out here. This is the simplest option already built into Emacs, and I've found it to be more than sufficient for ...
user avatar
  • 2,081
14 votes

How to recursively search / grep file contents in a directory / subdirectories in Emacs?

I happily use M-x find-grep-dired for years. It returns the results as a dired buffer, which you could use.
user avatar
10 votes

Recursive grep in directory with helm and/or projectile?

You have two ways: Use helm-projectile-grep/ack/ag: You can search for everything starting from project root. Later if you want to save the search results, press F3 or press TAB to switch to action ...
user avatar
  • 6,662
10 votes
Accepted

Is it possible to remove matches manually in grep mode?

Absolutely. And it is extremely useful to do that. M-x flush-lines and M-x keep-lines are your friends, as well as just C-k etc. (The first thing you need to do is of course C-x C-q, to make the ...
user avatar
  • 69.2k
6 votes

How to grep marked files in the dired mode of emacs?

If you use library Dired+ (dired+.el) then you can use command dired-do-grep (bound by default to M-g in Dired mode) to do what you request. diredp-do-grep is an interactive compiled Lisp function ...
user avatar
  • 69.2k
6 votes

emacs grep eliminate suspects

You can always make the *grep* buffer writable with C-x C-q and delete lines the normal way (e.g. with C-a C-k C-k). When you are done, press C-x C-q again to make it read-only if you wish and use TAB ...
user avatar
  • 19.6k
5 votes

rgrep : visiting matches without switching buffer

I'm awfully confused if you didn't actually try C-o, because by default that same binding does exactly what you want in grep buffers as well as in occur buffers. You can also simply navigate up and ...
user avatar
  • 43.1k
5 votes
Accepted

Read find-grep exclusion patterns from a .findignore file

Preferred solution I have settled with using "ag" (The Silver Searcher) for search and "helm-ag" or "ag.el" for Emacs integration. "ag" allows you to specify a ".agignore" file where you can add file/...
user avatar
5 votes
Accepted

Search files by content using full boolean expressions

Try using the UNIX or GNU/Linux find command. It supports Boolean operations. In Emacs you can, for example, use command find-dired, which runs find and puts the set of found files in a Dired buffer....
user avatar
  • 69.2k
5 votes

Recursive grep in directory with helm and/or projectile?

A recursive grep in a directory should be the simplest thing For a simple recursive grep inside current directory, just: M-x grep then, inside the minibuffer: Run grep (like this): grep -nHr "pattern"...
user avatar
  • 5,981
5 votes

How to recursively search / grep file contents in a directory / subdirectories in Emacs?

Solution 1 (best solution): Install counsel (https://github.com/abo-abo/swiper/blob/master/counsel.el) Then M-x counsel-git-grep. No setup needed (git knows the project root and files to exclude). ...
user avatar
  • 4,581
5 votes
Accepted

Advanced git grep from within emacs

I found the answer to my own question. It seems M-x grep is pretty powerful, in that it can handle any "grep like" shell command's output. So you can do M-x grep # it will ask you for the command, ...
user avatar
5 votes
Accepted

Grep pipe support and how to filter grep results

Note that the first grep grep --color=always -nH -e "text_to_find" ~/path/to/files/*.org puts escape sequences around matches for text_to_find to colorize those matches. If the second search string ...
user avatar
  • 29.9k
4 votes

How to recursively search / grep file contents in a directory / subdirectories in Emacs?

Here is an example of a custom grep function that recursively greps file contents (using a regexp for the search term) in a directory and its subdirectories, and displays the results with lines of ...
user avatar
  • 17.6k
4 votes

How to recursively search / grep file contents in a directory / subdirectories in Emacs?

I'd like to add another solution to @chen bin's solution which also uses counsel (but you don't need to have a project maintained by git for this). You need to install ag (the silver searcher) and ...
user avatar
4 votes

How to grep marked files in the dired mode of emacs?

(defun dired-grep-marked-files () "`i` case insensitive; `n` print line number; `I` ignore binary files; `E` extended regular expressions." (interactive) (let* ((files (dired-get-marked-files)) ...
user avatar
  • 17.6k
4 votes
Accepted

Jump to file and line number in grep file

The grep parameters you are using should be adequate. Just do M-x grep-mode after opening your results file and you should get the links you desire. You could also skip writing the grep results to a ...
user avatar
  • 6,794
4 votes

Grep pipe support and how to filter grep results

What you were attempting with a pipe works fine for me (tested in 26.1 and 25.3). Which version are you using? Does your command work outside of Emacs? Edit: C-hv grep-use-null-device might mess up ...
user avatar
  • 43.1k
3 votes

How can I create a new buffer for the second run of grep, to avoid overwriting the results of the first run of grep?

M-x rename-buffer. Use M-n to retrieve the current name, and edit it. E.g., M-n puts *grep*in the minibuffer. Type 1 to change it to *grep*1, etc. Then just use M-x grep again, to have the new ...
user avatar
  • 69.2k
3 votes
Accepted

How to grep marked files in the dired mode of emacs?

Eshell's grep is compatible with grep(1) and uses Emacs's internal grep interface, thus you can try something like the following: M-x dired-do-eshell-command RET grep -nH --color your-search--pattern ...
user avatar
  • 13.5k
3 votes

Is there a command in emacs similar to `find` in findutils?

find-dired will run find for you.
user avatar
3 votes

Multiple grep results buffers

You can do this easily if you use library Grep+ (grep+.el). Use + in your first *grep* buffer, followed by g. The + renames the first *grep* buffer by appending <N> (N=2,3,...) to it, and it ...
user avatar
  • 69.2k
3 votes
Accepted

How to grep all the Info manuals with a regexp search

The following solution relies upon three (3) command-line utilities: find; xargs; and zgrep. In putting together the following function, I discovered that grep cannot see inside gizipped files, and ...
user avatar
  • 17.6k
3 votes
Accepted

How to align grep output?

Here is the complete solution: (setcar (car grep-regexp-alist) "^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)[ \t]*\\2") (defun eab/grep-align () (interactive) (read-only-mode -1) (toggle-...
user avatar
  • 425
3 votes
Accepted

find-grep-dired: find exited abnormally with code 1

You need to use cygwin's or msys find command. The error messages shown above seem to come from the windows find command that is incompatible with emacs. See "Using grep' andfind' on MS Windows" on ...
user avatar
  • 1,051
3 votes

color rgrep matching results in the rgrep results buffer

grep (rgrep) uses two settings (that I know of) to control highlighting in the *grep* buffer font-lock-mode grep-highlight-matches - customization variable grep-highlight-matches depends on font-...
user avatar
  • 200
3 votes
Accepted

How to keep grep results in eshell buffer

eshell has several built-in commands (grep among them) and it prefers to use the built-in version: ~ $ which grep eshell/grep is a compiled Lisp function in ‘em-unix.el’. As the manual that I linked ...
user avatar
  • 19.6k
3 votes
Accepted

Filter text of buffer in a grep-like way

I want the text not matching the pattern to be gone M-x keep-lines will delete lines not matching the pattern (i.e. only keep the lines which match). flush-lines does the opposite, deleting lines ...
user avatar
  • 43.1k
2 votes

Emacs term loses characters when using ps and grep

As correctly guessed by Tyler, what's happening is that ps is truncating the output to the width of the terminal when it's running in Emacs Term, but not when it's running elsewhere. You can see that ...
user avatar

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