Search in all files in a project in Sublime Text 3

294,663

Solution 1

You can search a directory using FindFind in files. This also includes all opened tabs.

The keyboard shortcut is Ctrl+F on non-Mac (regular) keyboards, and +F on a Mac.

You'll be presented with three boxes: Find, Where and Replace. It's a regular Find/Find-replace search where Where specifies a file or directory to search. I for example often use a file name or . for searching the current directory. There are also a few special constructs that can be used within the Where field:

<project>,<current file>,<open files>,<open folders>,-*.doc,*.txt

Note that these are not placeholders, you type these verbatim. Most of them are self-explanatory (e.g. -*.doc excludes files with a .doc extension).

Pressing the ... to the right will present you with all available options.

After searching you'll be presented with a Find results page with all of your matching results. To jump to specific lines and files from it you simply double-click on a line.

Solution 2

You can put <project> in "Where:" box to search from the current Sublime project from the Find in Files menu.

This is more useful than searching from the root folder for when your project is including or excluding particular folders or file extensions.

Solution 3

Solution:

Use the Search all shortcut: Ctrl+Shift+F, then select the folder in the "Where:" box below. (And for Mac, it's +Shift+F).

If the root directory for the project is proj, with subdirectories src and aux and you want to search in all subfolders, use the proj folder. To restrict the search to only the src folder, use proj/src in the "Where: " box.

Solution 4

Right click on your root folder, find in folder.

enter image description here

Solution 5

Here's the easiest way : File -> Find in files

enter image description here

Share:
294,663
Ivan
Author by

Ivan

Data Scientist, Systems and Big Data Architect, Physicist

Updated on February 13, 2021

Comments

  • Ivan
    Ivan over 3 years

    Is there a way to search for a string in all files inside a project in Sublime Text 3? The string is not a method.

  • Ivan
    Ivan over 10 years
    Can you add info about the Where box?
  • Ivan
    Ivan over 10 years
    Thanks! I had to fiddle a bit with the "Where:". I thought it was from the project root, but if the root is proj and I want to search in proj/src, I have to type proj/src in Where.
  • Alexander Morland
    Alexander Morland almost 10 years
    Updated with info about Where box and how you can put <project> there
  • gmo
    gmo over 9 years
    <project> was a very nice trick!... Thank's for that. Also, (in case someone doesn't know and need it) you can define <open folders>, <open files>, filters... or mix them with a comma.
  • keyser
    keyser about 9 years
    @gmo yup, added info about those and the ... button now
  • soundly_typed
    soundly_typed about 9 years
    Instead of double-clicking on a line, is there a keyboard shortcut?
  • keyser
    keyser about 9 years
    @mindeavor You can cycle through the results using F4 (forward) and shift+F4 (backwards) on Windows. See the Find --> Find Results tab.
  • soundly_typed
    soundly_typed about 9 years
    @keyser Amazing! For the record, in the Find in files tab that opens up after searching, pressing F4 will also open the next result after your cursor! :D
  • Jim Hall
    Jim Hall over 8 years
    What about using splats or regex in the Where field? For example, I would like to do a search in all files with *-view.js in the file name.
  • Giancarlo Gomez
    Giancarlo Gomez over 8 years
    Thank you so much for the <project> trick. I was having an issue where Sublime 3 search was so slow when I had the full path to the directory project (network volumes only - fast on local) and adding <project> instead made it search FAST as hell again!!!
  • Labanino
    Labanino about 8 years
    @keyser I am using a WordPress starter kit for a new project and I want to replace the name of the theme. In Atom when you hit replace it does just that but in Sublime you get a result page. So, is there a shortcut for not clicking all results? because they are way to many!
  • ch271828n
    ch271828n about 8 years
    ⇧ means Shift. (I am such a fool to regard as up in the very beginning)
  • Muhammad Umer
    Muhammad Umer about 8 years
    can i do <project>/frontend
  • adibender
    adibender almost 8 years
    Is there a way to exclude a folder? Or folders with a certain name?
  • keyser
    keyser almost 8 years
    @adibender yes, you exclude stuff using the - prefix followed by a pattern that matches folders as well, for example -Test* to exclude any file or folder that starts with Test
  • adibender
    adibender almost 8 years
    @keyser Fantastic! Thank you very much!
  • WesternGun
    WesternGun over 6 years
    This is the way.... it does recursive search in the project. Only specifying folder does not work. Thanks!
  • Martin Thoma
    Martin Thoma over 6 years
    I don't see the "where:" box
  • Martin Thoma
    Martin Thoma over 6 years
    It's not there (anymore)
  • Mohammad Heydari
    Mohammad Heydari over 6 years
    Although it's not there anymore, it's for version 2
  • Merlin
    Merlin about 6 years
    is there a way to filter or sort results based on file modified date?
  • bantya
    bantya about 6 years
    The double click on find file line is what I was looking for. You saved my day!
  • Stiger
    Stiger almost 5 years
    It doesn't work. When I input Where(folder path on my mac) and File, it returns empty immediately, even that folder has thousand of files.
  • Elouan Keryell-Even
    Elouan Keryell-Even almost 5 years
    Too bad there are not placeholders, it would be cool to do <project>/sub/path :'(
  • hello_there_andy
    hello_there_andy over 4 years
    @WesternGun thanks you took the words out of my mouth but I still have another question, does it do recursive search from the root /? At which depth does it stop? Can we change this behaviour somehow to make it deeper?
  • WesternGun
    WesternGun over 4 years
    @hello_there_andy it does not begin from /, but from the folder you put into "Where". I think it will not stop at certain depth; it will reach till the very deepest, if you understand what I mean :)
  • hello_there_andy
    hello_there_andy over 4 years
    @WesternGun, i totally do know what you mean ;) perhaps the st3 i'm using needs to be updated, because there almost certainly is a max depth i tried it out using a test dir with many many sub dirs, and sub sub dirs... sigh. time to look at the config file
  • WesternGun
    WesternGun over 4 years
    In my PC 20 levels seems to be the upper limit for now. Maybe reducing some levels? It now is off-topic.
  • medmek
    medmek about 3 years
    would it be difficult to select a folder in the left panel and press ctrl+shift+F and have that folder automatically added to the Where field in the search (as jetbrain did)
  • medmek
    medmek about 3 years
    would it be difficult to select a folder in the left panel and press ctrl+shift+F and have that folder automatically added to the Where field in the search (as jetbrain did)
  • Jonathan Rys
    Jonathan Rys about 3 years
    I just updated to Build 4107 and this no longer works the same for me. Searching /Users/my_name/my_folder/ used to search in 3800+ files (with node_modules excluded) now it only searches in 760 files. Any ideas why this is the case? Not excluding node_modules makes it 2650 files searched now.