开发者

What's the best Find in File mode for EMACS?

What's the be开发者_C百科st package for finding a string in multiple files in EMACS. I know about grep and such but I would like something that is a little smoother to operate.


There are three builtin functions for grepping in Emacs: grep, find-grep (or grep-find) and rgrep.

The first two work by letting the user edit the grep command line directly. I usually use the third, rgrep, from "recursive grep". It's a little friendlier, as it prompts the user for the search parameters (search string, file types and directory) one by one, provides customizable defaults, and it automatically ignores some common files and directories you usually don't want to search, like for example .svn or .o files.

Then, there is ack, and its interface for Emacs: ack.el, whose default behavior is similar to rgrep, but can be customized to use the options that ack provides.


Just in case you haven't read it already - there's lots of relevant tips over at the EmacsWiki GrepMode page.


Dired mode also lets you do a search through marked files with the dired-do-search function.

And ibuffer lets you do emacs' generic isearch through a bunch of buffers using the awkward key sequence M-s a C-s.


As an alternative, I find dired-modehelpful, especially when used with either dired-mark-files-regexp (%m) or dired-mark-files-containing-regexp to select what should be searched and then dired-do-search (A).


Depends what you mean by find a string. As others have mentioned, grep is very good at what it does. I use it all the time, everyday.

But if your "string" is, say, a sequence of words within a sentence (which can be multi-line), then grep might not be what you want.

Another tool for searching across multiple files or buffers (or bookmarks) is Icicles search. The general idea is that it first parses the files into search contexts according to some definition (e.g. a regexp), and then it searches for matches to your current minibuffer input (changing the search hits dynamically as you edit your input).

Whereas grep always uses lines as search contexts, with Icicles search you are not limited in how you define the contexts to search. The contexts need not partition (exhaust) the file; they can cover as much or as little of the file text as you want.

Among other possibilities, you can use Emacs thing-at-point definitions for various kinds of THING as the search contexts. For example, you can use command icicles-search-thing with sentence as the THING type, to use sentences as the search contexts.

Or you can use character-property zones as search contexts: search all zones that are font-locked with a given set of faces, for instance. There are many possibilities.

http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜