Sublime text 2 find in folder with file extension - sublimetext2

How do I search in a folder in sublime text 2 with file extension?
My where when I use:
*.js
searches globally for all js files.
If I try to restrict it to a folder:
/project/*.js
it matches nothing.

Instead of this:
/project/*.js
Try using this:
project .js
This should match files which have project in the path and have a .js extension
EDIT: The above assumes you're trying to find all the files with .js extension using the Goto Anything feature in Sublime Text.
In case you'd like to search within .js files located within a directory, you can add an Include Filter in the search path:
/project,*.js
This will search for the text you've entered, limiting the scope to files within /project and it's sub-directories having the extension .js.
Reference: Sublime Text Docs - Search Scope
EDIT 2: For Sublime Text 3, refer Simons answer below.

godfrzero's answer does not work in Sublime 3 as it actually includes ALL JS files plus ALL files in the project folder.
Instead, you need to specify it similar to how you had it originally...
project/*.js
Note that there's no leading slash, as that will treat it as an absolute path which you won't want in most cases. To include multiple file types within the folder, I think you need to specify it like this:
folder/*.ctp,folder/*.php
This will match any of the following files:
/app/folder/example.ctp
/app/folder/example.php
/app/folder/subfolder/example.ctp
/app/long/path/folder/subfolder/example.php
I know you asked about Sublime 2, but hopefully this helps others (like myself) who are Googling for such advice.
Simon.

My Sublime ver: 3.2.2
Adding to above answers, I was trying to find in all python files starting with test_ . so this is how I did it.
After pressing Ctrl+Shift+F, in the window.
Where : /home/WorkDir/test, test_*.py

Related

Sublime Text 3 Default File Type on new file

I was looking around and the questions and answers did not seem to match what I am looking for (Sublime Text 3). Anytime I open a new file it defaults to a plain text file. I mostly work with PHP files so I was wondering if there is a setting that would be changed so that when I open a new file it will default to PHP.
I tried to find this directory path "Packages/Text/Plain_text.tmLanguage" here:
C:\Program Files\Sublime Text 3\Packages
C:\Users\user\AppData\Roaming\Sublime Text 3\Packages
But I did not find the "tmLanguage" files.
Reference: Sublime Text 2 - Default Document Type
The .tmLanguage files are within the .sublime-package files which are secretly simple archives holding all files necessary for a package to work.
Add a .zip extension to the .sublime-package file that contains the PHP settings and you can extract the .tmLanguage file you want as your new default.
Once you have that file, follow the instructions from the question you linked to and you should be good to go.
Set default file type in Sublime Text
Rather than messing with the files in your OS and adding a .zip extension to one of them …
… if you want to find the directory path to a built-in .sublime-syntax or a .tmLanguage file install PacakgeResourceViewer from Package Control.
After installing, use command palette to Package Resource Viewer: Open Resource and find PHP.sublime-syntax.
You can then see the path is Packages/PHP/PHP.sublime-syntax.
then:
Install DefaultFileType and edit its configuration file: Packages/User/default_file_type.sublime-settings as follows:
{ "default_new_file_syntax": "Packages/PHP/PHP.sublime-syntax",
"use_current_file_syntax": false }
Now your new files will default to sublime's built-in PHP syntax highlighting.

Sublime Text Editor: searching for files path

When I navigate files in Sublime Text Editor I use Ctrl+p to have it look for file names. Is there a similar function that lets me also use parts of the path as search parameter?
Ex: say I have two files with same name in /views and /controllers: how to return only the result in the controller folder when looking for something like filename controllers
You can already do this with ctrl+P, just use / to indicate that the previous part was a directory name:
WITHOUT specific directory
WITH specific directory

A PHP script file doesn't have PHP syntax formatting

In my PhpStorm, the file index.php, doesn't look like a PHP script, but a plain text file. How can I fix it?
Settings | File Types | Text files
Find and remove unwanted pattern there -- I expect this to be index.php or very similar
Similar SO questions:
PHPStorm renders a particular file name as plain text
Pycharm utils.py not getting syntax highlight
Follow this steps:
Open PHPStorm settings by using Ctrl+Alt+S
In search box type File types
Select file types option from left side panel
Find PHP Files (PHP) from Recognized file types
Check for .php extension in below area (Registered Patterns). If not found add PHP.
Right click on index.php and select "Mark as PHP".
(This option is there on PHPStorm 7.x, I'm not sure about 6.)

Compound file extension syntax coloring with Sublime Text 2

I have some files with the extension "js.php" that I would like Sublime to automatically treat as Javascript files not PHP files. Is this possible?
I tried adding "extensions": ["js.php"] to my user settings and then setting View->Syntax->Open All With Current Extension As ->Javascript (while a js.php file was open) but all files with just a .php extension were opened as Javascript files too.
Take a look at the ApplySyntax plugin. It was written to handle just such a scenario.

Issue in creating Zip file using glob.glob

I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better