Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim search text in folder

Tags:

vim

vim-plugin

Is there a way to search for some text in a folder and to display search results in a separate buffer in Vim? (Like Sublime Text Ctrl + Shift + F results)

like image 800
Just_Mad Avatar asked Sep 21 '12 07:09

Just_Mad


2 Answers

No, you don't need any plugin. The default :vimgrep (or :vim) is all you need.

Search for foo in every file in the current directory:

:vim foo * | cw

Search for foo in every JavaScript file in the current directory:

:vim foo *.js | cw

Search for foo in every JavaScript file in the current directory recursively:

:vim foo **/*.js | cw

Search for the current word in every file in the current directory:

:vim <C-r><C-w> * | cw
:vim <cword> * | cw

(edit: use :cw[indow] instead of :copen)

like image 103
romainl Avatar answered Oct 06 '22 00:10

romainl


Sounds like you need ack.vim:

This plugin is a front for the Perl module App::Ack. Ack can be used as a replacement for 99% of the uses of grep. This plugin will allow you to run ack from vim, and shows the results in a split window.

Usage:

:Ack [options] {pattern} [{directory}]
Search recursively in {directory} (which defaults to the current directory) for the {pattern}.

Files containing the search term will be listed in the split window, along with the line number of the occurrence, once for each occurrence. [Enter] on a line in this window will open the file, and place the cursor on the matching line.

like image 40
K Z Avatar answered Oct 06 '22 00:10

K Z