7

I would like to see all the lines from the current buffer, that contain some phrase, or match regex. Example:

My buffer:

dam madam
madam

this is da
m a
dam 1
dam 2
dam pi
dam 321:)
is dam 2?

Looking for dam. Result: dam madam dam 1 dam 2 dam pi dam 321:) is dam 2?

The same buffer. Looking for regexp: ^dam\s\d. Result: dam 1 dam 2 dam 321:)

How can I do this?

  • helm-swoop github.com/ShingoFukuyama/helm-swoop provides this as an interactive search, supporting regexps. It gives you a temporary menu of lines that match, from which you can quickly jump to one for editing – Tyler Dec 21 '15 at 15:43
  • 4
    Alternatively, the built-in function occur creates a new buffer that lists all the lines that match your regexp. Hitting e allows you to edit those lines directly from the occur buffer. – Tyler Dec 21 '15 at 15:48
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
  • Great! That's what I was looking for! – MatthewRock Dec 23 '15 at 0:09
1

Icicles multi-command icicle-occur (bound to C-' in Icicle mode) does this.

As you type into the minibuffer, the lines matching the pattern you type are shown as completion candidates. Your pattern can be as simple or as complex (e.g. a regexp) as you like. You can change the pattern dynamically, and the set of matches changes accordingly.

You can combine search patterns, that is, you can use any number of them to narrow the set of search hits. It is typically much easier to use two or more simple search patterns than it is to try to come up with a complex regexp that does exactly what you want. (But each of the individual search patterns can be as complex as you like.)

You can cycle among matches, or you can visit any of them, in any order. You can even replace matches selectively, on demand.

See the Overview of Icicles Search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.