美文网首页Emacs Lisp
Emacs高效检索文件内容及按文件名查找文件 2024-05-1

Emacs高效检索文件内容及按文件名查找文件 2024-05-1

作者: 齐格Insight | 来源:发表于2024-05-12 06:48 被阅读0次

背景

在日常工作中,有如下两类高效的检索文件场景:

  • 我们想根据关键字快速查找到当前目录文件中含相应内容的文件(检索文件内容)。
  • 我们能根据关键字快速找到到文件名含有该关键字的文件(按文件名查找文件)。

检索文件内容

ripgrep 按关键字检索,参考如下: BurntSushi/ripgrep: ripgrep recursively searches directories for a regex pattern while respecting your gitignore (github.com)

mac下安装ripgrep 直接使用brew brew install ripgrep
windows下安装ripgrep 直接使用winget winget install BurntSushi.ripgrep.MSVC

安装完成ripgrep后,就可以在命令行下检索了,效果如下:

image.png

如上图所示,我们找到两个文件有关键字pop-global 。这样查找内容就非常方便了。接下来我们将其配置在emacs,这样在emacs里也能使用rg进行检索内容:

配置方式:Using ripgrep in Emacs using helm-ag (Spacemacs) (github.com)

其要点是在Emacs中设置 helm-ag-base-command 这个变量。

M-x customize-set-variable helm-ag-base-command

将这个变量的值设置为:rg --vimgrep --no-heading --smart-case
如下:

image.png

然后在emacs执行以下命令可以查找当前项目里的内容,你可以绑定自己的快捷键:

M-x spacemacs/helm-project-do-ag

如下效果图:

image.png

按文件名查找文件

fd-find 按文件名进行查找,连接 sharkdp/fd: A simple, fast and user-friendly alternative to 'find' (github.com)

需要先安装fd
mac 下安装 brew install fd
windows下安装 winget install sharkdp.fd

安装完成后,可以进行查找测试,如下:fd "init"

image.png

emacs中配置fd,主要是将 ffip-use-rust-fd 变量设置为true。

image.png image.png

设置完成后,可以在emacs里使用M-x find-file-in-project-by-selected
效果如下:

image.png

相关文章

  • 简单的linux文件查找命令

    1、查找文件 2、查找文件夹(目录) 3、查找内容 4、只显示文件名称

  • find命令

    查找文件 find [路径] [参数] [条件] -name 按文件名称查找 find /etc/ -name ...

  • Linux 中高频使用的 find 命令汇总

    1、通过扩展名查找文件 find . -name ".txt"find / -name ".log" 2、按文件名...

  • linux常用的shell命令

    1.查找文件 根据文件名查找:find 路径 -name "xxx" 根据文件内容查找:grep -R 'xxx'...

  • Linux命令之find

    根据名称查找文件 find 路径 -name "文件名或通配符" 根据编辑时间查找文件

  • linux命令记录

    查找文件 find / -name fileName 在根目录中查找文件fileName 在文件中检索字符 ...

  • Linux文件查找和压缩

    查找命令 查找命令的完整文件名可用 which 或 type,这两个命令都是通过PATH变量来查找文件名 查找文件...

  • linux 个人日常小结(基础版)

    find 查找文件名find / -name 'filename' 跟路径 - name 文件名 awk 查找字符...

  • Python文件路径(102)

    传递给函数open()简单的文件名时,Python将在当前执行的文件(即.py程序文件)所在的目录查找文件(及不需...

  • Alfred使用方法

    简单查找文件:用快捷键呼出Alfred,键入空格,输入你要查找文件名,即可定位文件,回车打开,command+回车...

网友评论

    本文标题:Emacs高效检索文件内容及按文件名查找文件 2024-05-1

    本文链接:https://www.haomeiwen.com/subject/etrfdxtx.html