How to make VSCode Intellisense ignore certain folders but still have them appear in the Explorer window - visual-studio-code

I have a large C project which contains generated files among the source code. These will have names like g_*.c or be in directories named "out". I would like to have these generated files excluded from Intellisense, to speed up jump-to-definition. I have tried adding them to files.exclude:
"files.exclude": {
"**/g_*": true,
"**/out": true
}
However, this not only excludes them from Intellisense, but also removes them from the explorer window, so I cannot browse the files. Is there a way to exclude the files from Intellisense, but still make them appear in the Explorer window so that they are browsable?

Related

Why is my node_modules folder greyed out after command 'npm install'?

I wonder why my node_modules folder is greyed out in my VS Code editor after I run the command npm install.
Here the picture of my folder:
Files/folders that are included in .gitignore are greyed out. Normally node_modules folder is included within .gitignore.
It's because your node_modules folder is referenced in your .gitignore file.
Visual Studio tells you that this folder is ignored by the version control by graying it out.
As was already pointed out, VSCode automatically ignores everything in .gitignore. However, it also explicitely ignores some folders by default. All of this can be configured. Here are the steps you might want to take:
Check out the official documentation on Workspace settings
Open the relevant settings (you can choose between User (global) and Workspace). I usually do this via CTRL (or Command on Mac) + SHIFT + P -> > settings, which will show you the relevant choices: . For each you can either choose the UI or the JSON variant.
Also make sure to check the default settings via Peferences: Open Default Settings (JSON). You will find that, as of now (May 2021), **/node_modules is also automatically excluded, independent of other ignore files. Currently the default settings look like this:
// Configure glob patterns for excluding files and folders in fulltext searches and quick open. Inherits all glob patterns from the `files.exclude` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true
},
// Controls whether to use global `.gitignore` and `.ignore` files when searching for files.
"search.useGlobalIgnoreFiles": false,
// Controls whether to use `.gitignore` and `.ignore` files when searching for files.
"search.useIgnoreFiles": true,
Enabling searching node_modules
"search.exclude": {
"**/node_modules": false
},
"search.useIgnoreFiles": false
WARNING: This will slow down things a lot since node_modules takes forever to search through - at least during cold start, that is when things are not cached. (Note that it is difficult to estimate how their caching works since it keeps evolving over time.)
To mitigate this, you might want to add some additional search.exclude settings. Note you will have to explicitely list everything you don't want, because...
The big shortcoming of VSCode search
search.exclude does not support:
negative look-ahead/behind
mutually cascading queries
Things like this will not work!
// does NOT work! :((
"search.exclude": {
"**/node_modules/#types": false,
"**/node_modules": true
}
This is a MAJOR problem which has been heavily discussed in the almost famous issue #869 for 6 years already! Join in and add to the 100+ comments! :)
Update: As of 2021/8/14, the issue has been taken off the backlog queue and put in the On Deck queue (but that also might not mean much).

How to exclude all but certain files in the sidebar in Visual Studio Code?

Using Microsoft's Visual Studio Code, how do I show only certain files and file patterns in the sidebar and exclude all other files?
I want to show .yml files to achieve editing only them and not to scroll through all files.
I tried this, but it didn't work.
"files.exclude": {
"**/*": true,
"**/*.yml": false
}
P.S. I understand there is a way to hide certain files, but I want to show only specific files. I don't mind using an extension to achieve this.
This will get you pretty close:
"files.exclude": {
"**/*.[^y]*": true,
"**/*.y[^m]*": true,
"**/*.ym[^l]*": true
}
It should exclude all files except those starting with a .ym(etc.) extension, like .yml, .ym, .ymabcdef, etc. I don't know if you have any other files besides .yml that match that pattern. I think right now this is as close as you can get to what you want. The last entry doesn't seem to actually do anything though it should!!

How to filter files shown in Visual Studio Code?

How would you filter the files shown in the folder view in Visual Studio Code?
Reference: Filter files shown in folder
Hiding files and folders
The files.exclude setting lets you define patterns to hide files and folders from several places in VS Code like the explorer and search. Once defined, files and folders matching any of the patterns will be hidden.
{
"files.exclude": {
"**/*.js": true
}
}
Hide derived resources
If you use a language that compiles to another file at the same location of the source file, like TypeScript does to JavaScript, you can easily set an expression to hide those derived files:
"**/*.js": { "when": "$(basename).ts"}
Such a pattern will match on any JavaScript file (**/*.js), but only if a sibling file with the same name and extension, *.ts in this example, is present. The same technique can be used for other transpiled languages, like Coffee Script or Less/Sass, too.
Source: VS Code v0.5.0 (July 2015)
In version after VScode 1.70 (July 2022) all you need to do is press Ctrl+F or F3 to search.
Please refer following post
Searching in Explorer panel after VSCode 1.70
Only applicable for v1.69 and below.
Step #1
Click on Explorer window. This is critical as without focus on Explorer it will not work.
Step #2
Start Typing name you want to filter. It's weird that there is no textbox to take input but... take a leap of faith and type. You will see your typed text in top-right corner in brown background. Now hover on that text.
Step #3
Click on 3 stacked lines to filter..
They look like hamburger menu but they are not. They are saying if it's filtered or not. They are toggled between filtered and just highlight. So, make sure they are like inverted pyramid.
That's it. It should be filtered now.
If you only want to change the setting for this project, then do the following:
File > Save Workspace As > ... enter your {project name}
Then open file: {project name}.code-workspace
And update section settings.
Sample:
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.exclude": {
"**/*.log": true
}
}
}
VScode 1.70 (July 2022) should improve on this "tree filter" feature.
(Available today in Code insiders)
See issue 70646 and PR 152481:
Support find widget in lists/trees
This PR replaces the existing list/tree type filter:
with an bona fide find widget:
While a seemingly simple change, this has some (desired) consequences when searching/filtering in trees. Namely:
We will restore simple keyboard navigation by default.
That is: pressing the letter A will focus the next element which starts with A.
Initiating a search operation requires pressing Ctrl-F or F3, like the editor.
While searching, focus is in the find input box as opposed to the list itself.
Pressing DownArrow will focus the first list element which was found.
We'll preserve all custom behavior of context keys, eg. used by the VIM extension).
In VIM, the pre-existing / command will trigger simple keyboard navigation, as opposed to opening the find widget.
The VIM extension has the option to change this behavior themselves.
And:
In general:
Keyboard navigation is now called type navigation
Filter on type is now called find mode, aligned with a new find concept
Settings
workbench.list.keyboardNavigation has been renamed to workbench.list.defaultFindMode
workbench.list.automaticKeyboardNavigation has been deleted
Commands
list.toggleKeyboardNavigation has been renamed to list.triggerTypeNavigation
list.find has been added
list.closeFind has been added
list.toggleFilterOnType has been renamed to list.toggleFindMode
Context Keys
Mainly used by the vim extension:
listSupportsKeyboardNavigation has been renamed to listSupportsTypeNavigation
listAutomaticKeyboardNavigation has been renamed to listTypeNavigationMode
"With the focus on the File Explorer start to type part of the file name you want to match.You will see a filter box in the top-right of the File Explorer showing what you have typed so far and matching file names will be highlighted."
"Hovering over the filter box and selecting Enable Filter on Type will show only matching files/folders."
documentation: https://code.visualstudio.com/docs/getstarted/userinterface#_filtering-the-document-tree

How to hide files with specific extension in VSCode tree view

I use VSCode with Unity3D and I wonder is there any way to hide/ignore/filter certain types of files, for example *.meta files in VSCode's tree view? I cant find any suitable option in settings.
They have added this feature now. Go to File->Preferences->Workspace Settings. That opens or creates the .vscode folder, and underneath it the settings.json file.
Here is a full settings.json file that shows how to exclude the .git folder, the dist folder and the node_modules folder.
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/.git": true,
"dist": true,
"node_modules": true
}
}
Not at this time, but you can vote for the feature at the Visual Studio Code User Voice.
F1 > Preferences:Open Workspace Settings > [search settings] exclude >
Files:Exclude > Add Pattern
In other words, press F1 to open the thingy search thing, to find Preferences:Open Workspace Settings, then in the next search box, search for 'exclude', and add the pattern to exclude in the Files:Exclude section.
For example, to exclude all hidden backup files in Linux -- i.e. files with a tilde '~' on the end, add the pattern **/*~.
You might want to exclude the same pattern from the Search:Exclude and Files:Watcher Exclude sections.

How to avoid repeated matching items in Eclipse 'Open Resource'?

The project I'm working in uses Maven and its typical standar directory layout.
When I look for a resource with Eclipse 'Open Resource' I get these matches:
Where I get repeated matches.
There are only 2 XML files in filesystem.
The one under src/ and the one under target/.
For example, the path to the src/ file is:
maindev/common/utils/persistence/src/main/resources/com/ericsson/m2m/common/utils/persistence/impl/mybatis/custom/xml/
But 'Open Resource' indicates 3 matches for the same file with relative paths:
maindev/common/utils/persistence/src/...
common/utils/persistence/src/...
persistence/src/...
Is there a way in Eclipse to avoid those repeated matches?
Moreover, is there a way in Eclipse to indicate not to return resources for target/ directories?
NOTE: I tried Wojtek O. suggestion, but still getting matches:
You see multiple files because they logically are contained withing difference Eclipse projects. You could try to close some of those projects but that may as well result in compilation errors. If you wish to hide some files from the Open Resource... dialog you need to mark the folder containg those files as derived by right clicking on it in the Project Explorer and selecting Derived checkbox under Attributes section.
This is a really old thread, but in the newer Eclipse versions (Photon+) there's a filter option for resource search.
On the Open Resource dialog (Ctrl+Shift+R), click the drop-down on top "Enter resource name prefix..." and select "Filter Duplicated Resources".
If you're just looking for Java classes you can also use Open Type dialog (CTRL-Shift-T).