官术网_书友最值得收藏!

Searching across files

Vim has two commands to help you search across files, :grep and :vimgrep:

  • :grep uses system grep, and is a great tool if you're already familiar with how grep works
  • :vimgrep is a part of Vim, and might be easier to use if you are not already familiar with grep

We'll focus on :vimgrep, since the grep tool is outside the scope of this book.

The syntax is as follows: :vimgrep <pattern> <path>. pattern could either be a string or a Vim-flavored regular expression. path will often be a wildcard; use ** as a path to search recursively (or **/*.py to restrict by filetype).

Let's try searching for a calc substring in our code base:

:vimgrep animal **/* .py

This will take us to the first match, displaying the number of matches at the bottom of the screen:

To navigate through the matches, use :cn or :cp. However, you might want to open a visual quickfix window by using :copen, as follows:

You can navigate the quickfix list with the j and k keys and jump to a match by pressing Enter. The quickfix window can be closed like any other window by typing :q or running Ctrl + w, q. You can read more about it in the Quickfix List section in Chapter 5Build, Test, and Execute.

主站蜘蛛池模板: 睢宁县| 桂林市| 正阳县| 宜兰县| 盖州市| 长兴县| 沂源县| 怀来县| 乌鲁木齐市| 乌拉特前旗| 涟源市| 子洲县| 桂林市| 乌兰察布市| 凌海市| 米易县| 如东县| 石屏县| 交口县| 疏附县| 化州市| 曲阳县| 靖江市| 布尔津县| 东方市| 南投县| 固安县| 岑溪市| 黔西县| 突泉县| 滨海县| 安福县| 隆回县| 水城县| 肃宁县| 敦煌市| 芮城县| 南漳县| 广水市| 弋阳县| 阜南县|