How do I search in all files of my project using VIM?

感情迁移 提交于 2019-12-03 10:42:33

问题


There are a couple of things I do not yet understand the VIM way.

One of these is searching in a project like so (using VIM in Atom):

I use CtrlP currently for file names, but what about the contents?

How can I search with a string, and then look through a list of all occurrences using VIM and/or VIM plugins?


回答1:


I've found an even better solution for this: FZF

It simply searches through everything in your project asynchronously using the :Ag command.




回答2:


Use :grep or :vimgrep to search file contents. The results are put onto the "location list" which you can open by typing :cw Enter.

Syntax for :grep is, by default, the same as the grep(1) command:

:grep 'my pattern.*' /path/to/dir

By default it will search the current directory (:pwd).

The major difference between :grep and :vimgrep is that :vimgrep (:vim for short) uses Vim-compatible regular expressions, whereas :grep uses whatever regular expressions your &grepprg uses.

You can use a custom program by setting &grepprg to something different. I personally like ack which uses Perl-compatible regex.



来源:https://stackoverflow.com/questions/38398787/how-do-i-search-in-all-files-of-my-project-using-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!