简体   繁体   English

Emacs:使用正则表达式搜索缓冲区并在新缓冲区中显示结果?

[英]Emacs: search a buffer with regex and show results in a new buffer?

Supposed I had a buffer in emacs with 1000 lines, and dotted around in that buffer were unicode references (eg. \舦 ). 假设我在拥有1000行的emacs中有一个缓冲区,并且在该缓冲区中点缀了unicode引用(例如。 \舦 )。 I want to collect all those references into another buffer, which I can then sort and uniquify. 我想将所有这些引用收集到另一个缓冲区中,然后我可以对其进行排序和统一。

On the (*nix) command line, I can do something like: 在(* nix)命令行上,我可以执行以下操作:

grep -o "\\\\u[0-9]*" tmpfile | sort | uniq

Is this achievable directly within emacs, without saving any buffers to disk? 这是否可以直接在emacs中实现,而不将任何缓冲区保存到磁盘?

Go to your buffer, select it all with Cx h , then do M-| grep -o "\\\\\\\\u[0-9]*" | sort | uniq 转到缓冲区,用Cx h选择全部,然后执行M-| grep -o "\\\\\\\\u[0-9]*" | sort | uniq M-| grep -o "\\\\\\\\u[0-9]*" | sort | uniq M-| grep -o "\\\\\\\\u[0-9]*" | sort | uniq (this runs shell-command-on-region ). M-| grep -o "\\\\\\\\u[0-9]*" | sort | uniq (这运行shell-command-on-region )。 The output will go to *Shell Command Output* , which will not be shown unless the output is long enough, but it's always created and you can switch to it regardless. 输出将转到*Shell Command Output* ,除非输出足够长,否则不会显示,但它始终是创建的,无论如何都可以切换到它。

There is also occur ( Ms o ). 另外也occurMs o )。

 Mx occur RET [[:nonascii:]]+ RET Mx other-window Mx toggle-read-only Mx sort-lines 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM