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

SearchVimNeovim

Search Problem Overview


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):

enter image description here

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?

Search Solutions


Solution 1 - Search

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

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

enter image description here

Solution 2 - Search

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). I added set autochdir to my .vimrc so my PWD always follows the file I'm editing.

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.

Solution 3 - Search

To open a file, I highlight the row (Shift-v) in the location list and hit Enter.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSemView Question on Stackoverflow
Solution 1 - SearchSemView Answer on Stackoverflow
Solution 2 - SearchamphetamachineView Answer on Stackoverflow
Solution 3 - SearchVarun MuriyanatView Answer on Stackoverflow