美文网首页
Searching Files

Searching Files

作者: 一口亅 | 来源:发表于2021-05-04 18:55 被阅读0次

vim中打开文件——edit

:edit *.yml<Tab>
:edit **/*.md<Tab>
*是当前文件夹,**可以实现递归搜索

搜索文件——find

相对于edit,find可以查找路径下的文件
通过 :set path? 发现默认下的路径:

path=.,/usr/include,,
  • . means to search relative to the directory of the current file.
  • , means to search in the current directory.
  • /usr/include is the directory for C compilers header files.

通过在vimrc中添加路径快速读取文件

:set path+=$PWD/**

grep——文件中搜索

  • 两种语法
    • Internal grep (:vim. Yes, it is spelled :vim. It is short for :vimgrep).
  • External grep (:grep).

internal grep

:vim /pattern/ file

  • /pattern/ 搜索词的正则表达式模式
  • file是文件参数

e.g. 在app/controllers/目录中的所有ruby文件(.rb)中查找所有出现的“breakfast”字符串:
:vim /breakfast/ app/controllers/*/.rb

搜索之后的命令

:copen        Open the quickfix window
:cclose       Close the quickfix window
:cnext        Go to the next error
:cprevious    Go to the previous error
:colder       Go to the older error list
:cnewer       Go to the newer error list
To learn more about quickfix, check out :h quickfix.

external grep

:grep -R "lunch" app/controllers/

Browsing Files With Netrw

  • 前提
    vimrc中有两行命令
    set nocp
    filetype plugin on
  • 运行
    外部:
    vim .
    vim src/client/
    vim app/controllers/
    内部:
    :edit .
    :edit src/client/
    :edit app/controllers/
    不通过目录:
    :Explore Starts netrw on current file
    :Sexplore No kidding. Starts netrw on split top half of the screen
    :Vexplore Starts netrw on split left half of the screen

fzf——搜索插件

相关文章

网友评论

      本文标题:Searching Files

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