Emacs copy matching lines

后端 未结 5 1865
北恋
北恋 2020-12-13 16:13

In Emacs how can I easily copy all lines matching a particular regex? Preferably highlighting the matching lines as I type.

occur gets partway there by

5条回答
  •  -上瘾入骨i
    2020-12-13 16:33

    As of Emacs 24, occur does in fact provide a simple solution:

    C-uM-so .*pattern.* RET

    When you use C-u on its own as the prefix argument, the matching portion of each line is inserted into the *Occur* buffer, without all the normal adornments.

    Note that because only the part of the line matching the regexp is used (unlike a normal occur), you need the leading and trailing .* to ensure that you capture the entire line.

    The details of how occur treats arguments are a little tricky, so read C-hf occur RET carefully if you want to know more.

提交回复
热议问题