0

Emacs 26.1, Windows 10

If I want to show all lines content text in one line I use command occur

M-x occur text_to_find

Nice. It's work fine.

But how I can use occurif text to find is on 2 lines?

E.g.:

aaa bb cccc
test this text_to_find hello how I your?
result is very good
ddd eee ffff

enter image description here

So I need to show all lines content the next text (in 2 lines)

text_to_find

result

5
  • Is the line containing result must be right after the text_to_find line, or do you just want to search two keywords at the same time( use \(text_to_find\|result\) as regexp pattern in this case)?
    – whatacold
    Feb 8, 2019 at 12:57
  • No. The word "result" is NOT right after the text_to_find. It's after some words on the the NEXT line. Feb 8, 2019 at 13:19
  • @whatacold I updated my post Feb 8, 2019 at 13:21
  • In connection with your question about copying multiple files into one maybe elgrep is the right tool for you. It searches multiple files for matches of regular expressions. It also provides the command elgrep-menu where you are guided by a menu and have control over almost all options of elgrep.
    – Tobias
    Feb 8, 2019 at 14:19
  • Note that there are also other tools that search multiple files such as multi-occur.
    – Tobias
    Feb 8, 2019 at 14:21

1 Answer 1

4

You have to use a literal C-j to match the newline, which you can etnter by prefixing it with C-q, i.e.

M-x occur RET text-to-find.*C-qC-j.*result

(occur also takes a prefix argument that tells it how many lines of context to show, which can be useful too).

1
  • "occur also takes a prefix argument that tells it how many lines of context to show, which can be useful too" - it's very cool. Thanks Feb 8, 2019 at 13:29

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.